[clang] [clang-tools-extra] [libcxx] [clang] fix diagnostic printing of expressions ignoring LangOpts (PR #134693)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 8 10:51:49 PDT 2025


================
@@ -7379,6 +7379,14 @@ class RecoveryExpr final : public Expr,
   friend class ASTStmtWriter;
 };
 
+/// Insertion operator for diagnostics.  This allows sending
+/// Expr into a diagnostic with <<.
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+                                             const Expr *E) {
+  DB.AddTaggedVal(reinterpret_cast<uint64_t>(E), DiagnosticsEngine::ak_expr);
----------------
mizvekov wrote:

Yes, I had carefully reviewed it and I think it was fine, given the circumstances.

For reference, here are all the other uses:
```C++
clang/include/clang/AST/Attr.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(At), DiagnosticsEngine::ak_attr);
clang/include/clang/AST/Expr.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(E), DiagnosticsEngine::ak_expr);
clang/include/clang/AST/NestedNameSpecifier.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(NNS),
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(reinterpret_cast<intptr_t>(Str),
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(static_cast<unsigned>(I), DiagnosticsEngine::ak_tokenkind);
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(reinterpret_cast<intptr_t>(II),
clang/include/clang/Basic/Diagnostic.h:  DB.AddTaggedVal(reinterpret_cast<intptr_t>(DC),
clang/include/clang/Basic/PartialDiagnostic.h:        DB.AddTaggedVal(DiagStorage->DiagArgumentsVal[i],
clang/include/clang/Sema/ParsedAttr.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(At.getAttrName()),
clang/include/clang/Sema/ParsedAttr.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(At->getAttrName()),
clang/include/clang/Sema/ParsedAttr.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI.getAttrName()),
clang/include/clang/Sema/ParsedAttr.h:  DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI->getAttrName()),
```

So 6 uint64_t vs 3 intptr_t (excluding this patch). Without going on and changing everything else, there is no single answer here which would be satisfy everyone.

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


More information about the cfe-commits mailing list