[PATCH] D133194: rewording note note_constexpr_invalid_cast

Muhammad Usman Shahid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 2 03:11:27 PDT 2022


Codesbyusman created this revision.
Codesbyusman added reviewers: aaron.ballman, erichkeane, xgupta.
Herald added a project: All.
Codesbyusman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The diagnostics here are correct, but the note is really silly. It talks about reinterpret_cast in C code. So rewording it for c mode by using more select.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133194

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13566,7 +13566,8 @@
   }
 
   case CK_PointerToIntegral: {
-    CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
+    CCEDiag(E, diag::note_constexpr_invalid_cast)
+        << 2 << Info.Ctx.getLangOpts().CPlusPlus;
 
     LValue LV;
     if (!EvaluatePointer(SubExpr, LV, Info))
Index: clang/include/clang/Basic/DiagnosticASTKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticASTKinds.td
+++ clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -11,8 +11,9 @@
 // Constant expression diagnostics. These (and their users) belong in Sema.
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
-  "%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
-  " a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
+  "%select{reinterpret_cast|dynamic_cast|%select{this conversion|cast that"
+  " performs the conversions of a reinterpret_cast}1|cast from %1}0"
+  " is not allowed in a constant expression"
   "%select{| in C++ standards before C++20||}0">;
 def note_constexpr_invalid_downcast : Note<
   "cannot cast object of dynamic type %0 to type %1">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133194.457549.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220902/01ff7e47/attachment.bin>


More information about the cfe-commits mailing list