[PATCH] D130894: [clang] Print more information about failed static assertions

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 09:03:08 PDT 2022


aaron.ballman added a comment.

In D130894#3696590 <https://reviews.llvm.org/D130894#3696590>, @xbolva00 wrote:

> Use ‘5 ==6’ ? So add quotes ..

+1 to the suggestion to use quotes for a bit of visual distinction between the diagnostic message and the code embedded within it.



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16573-16584
+      if (BoolValue) {
+        Str.push_back('t');
+        Str.push_back('r');
+        Str.push_back('u');
+        Str.push_back('e');
+      } else {
+        Str.push_back('f');
----------------
Thankfully, there is a better way: 
```
llvm::raw_svector_ostream OS(Str);
OS << (BoolValue ? "true" : "false");
```
which applies to the other cases in this function as well.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16647-16649
+  if (isa<IntegerLiteral>(E) || isa<FloatingLiteral>(E) ||
+      isa<CharacterLiteral>(E) || isa<CXXBoolLiteralExpr>(E) ||
+      isa<CXXNullPtrLiteralExpr>(E))
----------------
`FixedPointLiteral`? `ImaginaryLiteral`?


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16658
+  // -5 is also simple to understand.
+  if (const UnaryOperator *UnaryOp = dyn_cast_or_null<UnaryOperator>(E))
+    return UsefulToPrintExpr(UnaryOp->getSubExpr());
----------------



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16672
+void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
+  if (const BinaryOperator *Op = dyn_cast_or_null<BinaryOperator>(E)) {
+    const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
----------------



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130894/new/

https://reviews.llvm.org/D130894



More information about the cfe-commits mailing list