mirror-llvm-project/clang/lib/Lex
Sirraide 75b5df8f0a
[Clang] Support libstdc++ workarounds when using -E (#210802)
We have a libstdc++ workaround in place to address a hack in libstdc++15
that is used in the definition of `std::format_kind`. GCC accepts the
hack, while Clang does not. libstdc++ was eventually updated to remove
the hack, but we still need the workaround for some versions of
libstdc++15 (see #139560 for more information).

Whether this workaround (and others that address libstdc++ hacks) is
active depends on the value of `__GLIBCXX__`. This stops working if
someone first preprocesses the input (via `-E`) and then attempts to
compile the preprocessed code with Clang (see #160314): since
preprocessing has already happened, `__GLIBCXX__` will be undefined and
the workaround will not be applied.

In case of this particular workaround, this results in `#include
<format>` failing to compile on some versions of libstdc++ if you’re
using separate preprocessing.

To resolve this problem, this patch introduces a new pragma (`#pragma
clang __set_pp_state MACRO_NAME INTEGER`). This is intended as a general
solution to preserving preprocessor state across runs of the
preprocessor.

Currently, the only supported value for `MACRO_NAME`is `__GLIBCXX__`.
When we encounter this form of the pragma, we update
`Preprocessor::CXXStandardLibraryVersion` (we don’t actually define
`__GLIBCXX__` or do anything w/ that macro here). In `-E` mode, the
pragma is retained in the output, and a pragma is emitted for `#define
__GLIBCXX__` if printing macro definitions is disabled.

Things like `#undef __GLIBCXX__` and redefinitions of `__GLIBCXX__` are
deliberately left unhandled (i.e. you get what you get), since users
shouldn’t ever be undefining or redefining this macro anyway (and since
it starts w/ `__`, it would also be UB to do so).

Fixes #160314.
2026-07-30 18:09:08 +02:00
..
CMakeLists.txt Enable fexec-charset option (#138895) 2026-07-02 13:38:50 -04:00
DependencyDirectivesScanner.cpp Reapply "[ObjC][Preprocessor] Handle @import directive as a pp-directive" (#189174) 2026-04-16 07:53:00 +08:00
HeaderMap.cpp [clang] Remove unused includes (NFC) (#144285) 2025-06-15 21:00:36 -07:00
HeaderSearch.cpp [clang][lex] Store HeaderFileInfo in a MapVector (#201936) 2026-06-05 15:06:57 -07:00
InitHeaderSearch.cpp [clang] Add support for SerenityOS (#187941) 2026-04-14 10:04:24 -07:00
Lexer.cpp [Clang] Implement P3658R1 (#212131) 2026-07-28 07:46:23 +02:00
LexHLSLRootSignature.cpp [HLSL][RootSignature] Correct RootSignatureParser to use correct SourceLocation in diagnostics (#147084) 2025-07-08 09:55:51 -07:00
LiteralSupport.cpp Silence a signed/unsigned mismatch diagnostic; NFC (#208088) 2026-07-07 17:31:33 -04:00
MacroArgs.cpp
MacroInfo.cpp [clang] Remove unused includes (NFC) (#146254) 2025-06-28 20:41:46 -07:00
ModuleMap.cpp Reapply "[clang] Use FileError in FileManager::getFileRef, getDirectoryRef" (#199759) 2026-05-27 10:47:51 -07:00
ModuleMapFile.cpp [clang][modules] Add warning for module maps with ".." paths (#184279) 2026-03-05 11:29:31 -08:00
PPCaching.cpp [clangd] fix preprocessor caching-lexer state tracking (#203716) 2026-06-23 23:25:02 +08:00
PPCallbacks.cpp
PPConditionalDirectiveRecord.cpp
PPDirectives.cpp [Clang] Treat line directives as header names. (#211512) 2026-07-29 19:04:17 +02:00
PPExpressions.cpp [Clang] Support libstdc++ workarounds when using -E (#210802) 2026-07-30 18:09:08 +02:00
PPLexerChange.cpp [clangd] fix preprocessor caching-lexer state tracking (#203716) 2026-06-23 23:25:02 +08:00
PPMacroExpansion.cpp [clang][NFC] move traits to tablegen (#201491) 2026-07-20 06:50:22 -07:00
Pragma.cpp [Clang] Support libstdc++ workarounds when using -E (#210802) 2026-07-30 18:09:08 +02:00
PreprocessingRecord.cpp
Preprocessor.cpp [Clang] Support libstdc++ workarounds when using -E (#210802) 2026-07-30 18:09:08 +02:00
PreprocessorLexer.cpp
ScratchBuffer.cpp
TextEncoding.cpp Change ToLiteralEncodingConverter to a unique_ptr (#207258) 2026-07-03 11:04:19 -04:00
TokenConcatenation.cpp [Clang] Supports dollars in UDLs and pp-numbers (#208490) 2026-07-10 15:42:16 +02:00
TokenLexer.cpp [clang] Suggest using __VA_OPT__(,) instead of GNU zero variadic macro argument (#188624) 2026-04-01 12:09:02 +00:00
UnicodeCharSets.h [Clang] Implement P3658R1 (#212131) 2026-07-28 07:46:23 +02:00