2 Commits

Author SHA1 Message Date
Oleksandr Tarasiuk
bf7e2b81e7
[Clang] prevent preprocessor crash on incomplete scoped __has_cpp_attribute arguments (#178273)
Fixes #178098

---

This patch addressed the issue when `__has_cpp_attribute` is expanded
with incomplete scoped attributes. The scoped name parsing can lex to
`eof`/`eod` at


3f5a5d45d1/clang/lib/Lex/PPMacroExpansion.cpp (L1877-L1881)

and then proceed with


3f5a5d45d1/clang/lib/Lex/PPMacroExpansion.cpp (L1425-L1430)


since `eof`/`eod` is not guarded at


3f5a5d45d1/clang/lib/Lex/PPMacroExpansion.cpp (L1367-L1372)

this could lead to a preprocessor crash


3f5a5d45d1/clang/lib/Lex/PPMacroExpansion.cpp (L1370)
2026-01-28 15:44:48 +02:00
Aaron Ballman
2edb89c746 Lex arguments for __has_cpp_attribute and friends as expanded tokens
The C and C++ standards require the argument to __has_cpp_attribute and
__has_c_attribute to be expanded ([cpp.cond]p5). It would make little sense
to expand the argument to those operators but not expand the argument to
__has_attribute and __has_declspec, so those were both also changed in this
patch.

Note that it might make sense for the other builtins to also expand their
argument, but it wasn't as clear to me whether the behavior would be correct
there, and so they were left for a future revision.
2021-10-17 07:54:48 -04:00