Fix C++20 build: don't name constructors with a template-id#77
Open
darrylabbate wants to merge 1 commit into
Open
Fix C++20 build: don't name constructors with a template-id#77darrylabbate wants to merge 1 commit into
darrylabbate wants to merge 1 commit into
Conversation
GCC 15 (the default compiler on Ubuntu 26.04) and other modern C++20
toolchains reject a template-id as a constructor declarator:
error: template-id not allowed for constructor in C++20
[-Werror=template-id-cdtor]
The DEFINE_INHERITED macro expands its first argument into the
constructor declarator (`CLASS() { ... }`). For the templated benchmark
classes, that argument was the full template-id, e.g.
DEFINE_INHERITED(GLUE_TYPENAME(OriginalBenchmark<bs, fn_ptr>), bs);
which expands to `OriginalBenchmark<bs, fn_ptr>() { ... }` -- a
constructor named with a template-id, forbidden under C++20. Because
IMB's Makefile builds with -Werror, this breaks the whole build on
GCC 15.
Pass the bare class name (the injected-class-name) instead of the
template-id at the three templated call sites (OriginalBenchmark,
BenchmarkMT, HaloBenchmark). Inside a class template the
injected-class-name denotes the current instantiation, so both the
`new CLASS` expression and the `CLASS()` constructor declarator remain
correct, while the constructor is no longer spelled with a template-id.
The non-templated call sites already pass a plain class name and are
unchanged.
Builds clean with GCC 15.2 (-Wall -Wextra -Werror, default C++17 and
under -std=c++20) with no other changes.
Signed-off-by: Darryl Abbate <drl@amazon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GCC 15 (the default compiler on Ubuntu 26.04) and other modern C++20 toolchains reject a template-id as a constructor declarator:
The DEFINE_INHERITED macro expands its first argument into the constructor declarator (
CLASS() { ... }). For the templated benchmark classes, that argument was the full template-id, e.g.which expands to
OriginalBenchmark<bs, fn_ptr>() { ... }-- a constructor named with a template-id, forbidden under C++20. Because IMB's Makefile builds with -Werror, this breaks the whole build on GCC 15.Pass the bare class name (the injected-class-name) instead of the template-id at the three templated call sites (OriginalBenchmark, BenchmarkMT, HaloBenchmark). Inside a class template the injected-class-name denotes the current instantiation, so both the
new CLASSexpression and theCLASS()constructor declarator remain correct, while the constructor is no longer spelled with a template-id. The non-templated call sites already pass a plain class name and are unchanged.Builds clean with GCC 15.2 (-Wall -Wextra -Werror, default C++17 and under -std=c++20) with no other changes.