Includes of stddef.h after the first include do not respect include guards with c++23
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Includes of stddef.h after the first include should have no effect due to the include guard, but the stddef.h builtin header provided with Clang Modules don't seem to abide by this.
With the following input code:
a.cpp:
```c++
#include
static char a = {
#include
0
};
int main { return 0; }
```
This works:
clang -std=c++17 a.cpp
It works with clang 18.1.0, but breaks with clang 17.1.0, and starting from clang 19.1.0 onward:
clang -std=c++23 a.cpp
```
Output of x86-64 clang 21.1.0 (Compiler #1)
In file included from :4:
In file included from /cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_21.1.0/lib/clang/21/include/stddef.h:88:
/cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_21.1.0/lib/clang/21/include/__stddef_ptrdiff_t.h:18:1: error: expected expression
18 | typedef __PTRDIFF_TYPE__ ptrdiff_t;
| ^
1 error generated.
ASM generation compiler returned: 1
In file included from :4:
In file included from /cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_21.1.0/lib/clang/21/include/stddef.h:88:
/cefs/d2/d2e6ebb9fe16525f6e7eb0c3_consolidated/compilers_c++_clang_21.1.0/lib/clang/21/include/__stddef_ptrdiff_t.h:18:1: error: expected expression
18 | typedef __PTRDIFF_TYPE__ ptrdiff_t;
| ^
1 error generated.
Execution build compiler returned: 1
Build failed
```
This was reported on the LTTng-UST bug tracker: https://bugs.lttng.org/issues/1435
Contributor guide
Research direction
Start by reproducing the example in a.cpp with clang -std=c++23, then compare the behavior across the reported Clang versions. Read the builtin stddef.h and __stddef_ptrdiff_t.h files named in the diagnostic; done means the second include has no effect and the example compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100