[Clang] On GCC, C23 `typeof` strips `noreturn` attribute on function pointers
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/e8M18778s
```C
[[gnu::noreturn]]
extern void(*fptr)(void);
int typeof_ext(int i, __typeof(fptr) p) {
p();
return i; // not emitted because p is noreturn
}
int typeof_std(int i, typeof(fptr) p) {
p();
return i; // emitted on GCC C23
}
```
When under C23 and using the standard (not underscored) spelling of `typeof`, GCC would remove the `noreturn` attribute from the function pointer type.
From GCC's commit message (https://github.com/gcc-mirror/gcc/commit/fa258f6894801aef6785f0327594dc803da63fbd) this seems to be intentional.
Could be dangerous if someone rely on this behavior and only test with GCC.
Contributor guide
Research direction
Start with the Compiler Explorer reproduction at https://godbolt.org/z/e8M18778s and compare the standard and underscored typeof spellings under C23. Trace Clang's C23 typeof handling and add a regression test covering preservation of the noreturn attribute on function-pointer types; done means the two spellings have the intended, consistent behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100