Skip to content

Clang 22 error: '__COUNTER__' is a C2y extension [-Werror,-Wc2y-extensions] #3076

Closed

Description

@offa

Describe the bug

Build tests with Clang 22 causes '__COUNTER__' is a C2y extension warnings on all usages of TEST_CASE(…).

Simplified example:

#include <catch2/catch_test_macros.hpp>

// ...

TEST_CASE("Connection tests", "[ConnectionTests]") { // <<<-- Line 66
    // ...
}

Compilation result:

__w/seasocks/seasocks/src/test/c/ConnectionTests.cpp:66:1: error: '__COUNTER__' is a C2y extension [-Werror,-Wc2y-extensions]
   66 | TEST_CASE("Connection tests", "[ConnectionTests]") {
      | ^
/__w/seasocks/seasocks/build/_deps/catch2-src/src/catch2/../catch2/catch_test_macros.hpp:151:28: note: expanded from macro 'TEST_CASE'
  151 |   #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
      |                            ^
/__w/seasocks/seasocks/build/_deps/catch2-src/src/catch2/../catch2/internal/catch_test_registry.hpp:118:35: note: expanded from macro 'INTERNAL_CATCH_TESTCASE'
  118 |         INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__ )
      |                                   ^
/__w/seasocks/seasocks/build/_deps/catch2-src/src/catch2/../catch2/internal/catch_unique_name.hpp:15:85: note: expanded from macro 'INTERNAL_CATCH_UNIQUE_NAME'
   15 | #  define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
      |                                                                                     ^

Expected behavior

No error or warning emitted.

Reproduction steps

  1. Build a test with Clang 22

Platform information:

  • OS: Linux
  • Compiler+version: Clang 22.1.1
  • Catch version: v3.13.0

Additional context

Enabled compiler warnings: -Wall -Werror -Wextra -pedantic -pedantic-errors

Activity

  1. added a commit that references this issue on Mar 11, 2026
    b2d30b7
  2. horenmar commented on Mar 31, 2026

    @horenmar
    Member

    So, I looked into this and the result is not great.

    In theory, we can add _Pragma to remove the warnings. In practice, we will have to suppress the warning for the whole TU, as Clang currently doesn't handle the warning and its suppression correctly: llvm/llvm-project#189645.

  3. offa commented on Mar 31, 2026

    @offa
    ContributorAuthor

    Thanks for filing the llvm issue!

  4. added a commit that references this issue on Apr 1, 2026
    51b0532
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions