Skip to content

[Clang] Clang headers use unreserved identifiers #161808

@mstorsjo

Description

@mstorsjo

Since Clang 20.x (in particular, since 83ad644), the Clang intrinsics headers use unreserved identifiers. This can break user code that does e.g. #define A ... before including the headers.

This does come up in real user code - more than one may expect. As long as the Clang intrinsics headers don't get included in the same translation unit, there's no issue, but once such an include creeps in implicitly, things break.

This also triggers on libcxx's corresponding test to make sure their headers are free of such identifiers, when the Clang intrinsics headers get included implicitly through WinSDK/UCRT headers. (See #161736 for that case.)

To reproduce the issue, try the following:

#define A this identifier should not be used by system headers
#define B this identifier should not be used by system headers
#include <x86intrin.h>
$ clang -c intrin-test.c
In file included from intrin-test.c:3:
In file included from /llvm-project/llvm/build/lib/clang/22/include/x86intrin.h:15:
In file included from /llvm-project/llvm/build/lib/clang/22/include/immintrin.h:500:
/llvm-project/llvm/build/lib/clang/22/include/avx10_2bf16intrin.h:522:69: error: expected ')'
  522 | static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comieq_sbh(__m128bh A,
      |                                                                     ^
intrin-test.c:1:16: note: expanded from macro 'A'
    1 | #define A this identifier should not be used by system headers
      |                ^

A similar issue was reported and fixed before in #98478, where @AaronBallman suggested that the Clang headers should use https://clang.llvm.org/extra/clang-tidy/checks/bugprone/reserved-identifier.html.

Metadata

Metadata

Labels

clang:headersHeaders provided by Clang, e.g. for intrinsics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions