[clang] [Clang] Improve infrastructure for libstdc++ workarounds (PR #141977)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri May 30 06:44:04 PDT 2025


================
@@ -979,3 +979,50 @@ Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro,
   return EvaluateDirectiveExpression(IfNDefMacro, Tok, EvaluatedDefined,
                                      CheckForEoD);
 }
+
+static std::optional<CXXStandardLibraryVersionInfo>
+getCXXStandardLibraryVersion(Preprocessor &PP, StringRef MacroName,
+                             CXXStandardLibraryVersionInfo::Library Lib) {
+  MacroInfo *Macro = PP.getMacroInfo(PP.getIdentifierInfo(MacroName));
+
+  if (!Macro || Macro->getNumTokens() != 1)
+    return std::nullopt;
+
+  const Token &RevisionDateTok = Macro->getReplacementToken(0);
+
+  bool Invalid = false;
+  llvm::SmallVector<char, 10> Buffer;
+  llvm::StringRef RevisionDate =
+      PP.getSpelling(RevisionDateTok, Buffer, &Invalid);
+  if (!Invalid) {
+    unsigned Value;
+    // We don't use NumericParser to avoid diagnostics
+    if (!RevisionDate.consumeInteger(10, Value))
+      return CXXStandardLibraryVersionInfo{
+          CXXStandardLibraryVersionInfo::LibStdCXX, Value};
----------------
erichkeane wrote:

So it seems weird to me that the `macro name` is sent to this function, and thus could be basically anything, but we set this always to `LibStdCXX`.  It seems to me that the 1st part of this should be `Lib`, right? 

https://github.com/llvm/llvm-project/pull/141977


More information about the cfe-commits mailing list