[all-commits] [llvm/llvm-project] 75b5df: [Clang] Support libstdc++ workarounds when using `...

Sirraide via All-commits all-commits at lists.llvm.org
Thu Jul 30 09:09:31 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 75b5df8f0af1000cae8e21fedbc14d0c51a01318
      https://github.com/llvm/llvm-project/commit/75b5df8f0af1000cae8e21fedbc14d0c51a01318
  Author: Sirraide <aeternalmail at gmail.com>
  Date:   2026-07-30 (Thu, 30 Jul 2026)

  Changed paths:
    M clang/docs/ReleaseNotes.md
    M clang/include/clang/Basic/DiagnosticLexKinds.td
    M clang/include/clang/Lex/PPCallbacks.h
    M clang/include/clang/Lex/Preprocessor.h
    M clang/lib/Frontend/PrintPreprocessedOutput.cpp
    M clang/lib/Lex/PPExpressions.cpp
    M clang/lib/Lex/Pragma.cpp
    M clang/lib/Lex/Preprocessor.cpp
    A clang/test/Preprocessor/pragma_set_pp_state.cpp
    M clang/test/SemaCXX/libstdcxx_format_kind_hack.cpp

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list