Skip to content

Fix C++20 build: don't name constructors with a template-id#77

Open
darrylabbate wants to merge 1 commit into
intel:mainfrom
darrylabbate:fix-c++20-template-id-cdtor
Open

Fix C++20 build: don't name constructors with a template-id#77
darrylabbate wants to merge 1 commit into
intel:mainfrom
darrylabbate:fix-c++20-template-id-cdtor

Conversation

@darrylabbate

Copy link
Copy Markdown

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant