[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 10 12:29:09 PST 2024


================
@@ -711,11 +712,54 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
   case APValue::Indeterminate:
     Out << "<uninitialized>";
     return;
-  case APValue::Int:
+  case APValue::Int: {
+    const APSInt &Val = getInt();
+    if (const EnumType *ET = Ty->getAs<EnumType>()) {
+      // print the enumerator name if requested (and one exists)
+      if (Policy.UseEnumerators) {
+        for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) {
+          if (APSInt::isSameValue(ECD->getInitVal(), Val)) {
+            if (ECD->isCXXClassMember())
+              ECD->printQualifiedName(Out, Policy);
+            else
+              ECD->printName(Out, Policy);
----------------
sethp wrote:

This is a weird heuristic: without it, we were trying to print a function-local enum constant as `fn_name()::Constant`.

It might be better to go back to just always using the QualifiedName though, I'm not sure.

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


More information about the cfe-commits mailing list