[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 05:26:04 PDT 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);
+ return;
+ }
+ }
+ }
+
+ // otherwise, we print it as a cast from `Val`
+ if (ET->hasUnnamedOrLocalType()) {
+ // e.g. `(unnamed enum at ...)7`, unless...
+ if (const EnumDecl *Defn = ET->getDecl()->getDefinition()) {
+ // ... can identify the defn somehow
+ if (const IdentifierInfo *II = Defn->getIdentifier())
+ Out << '(' << II->getName() << ')';
+ else if (const TypedefNameDecl *Typedef =
+ Defn->getTypedefNameForAnonDecl()) {
+ assert(Typedef->getIdentifier() && "Typedef without identifier?");
+ Out << '(' << Typedef->getIdentifier()->getName() << ')';
+ } else if (const NamedDecl *ND = dyn_cast_if_present<NamedDecl>(
+ Defn->getNextDeclInContext())) {
+ // if it's part of a declaration, then use `(decltype(...))7`
+ Out << "(decltype(";
+ ND->printQualifiedName(Out);
+ Out << "))";
----------------
cor3ntin wrote:
Does it really make sense to support the unnamed case?
https://github.com/llvm/llvm-project/pull/74852
More information about the cfe-commits
mailing list