[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
================
@@ -17256,6 +17378,56 @@ static bool ConvertAPValueToString(const APValue &V, QualType T,
OS << "i)";
} break;
+ case APValue::ValueKind::Array:
+ case APValue::ValueKind::Vector: {
+ llvm::raw_svector_ostream OS(Str);
+ // we hope to emit a valid initalizer expression
+ // like `(const int[3]){1, 2, 3}`
+ OS << '(' << T << ')';
+ PrintingPolicy Policy(Context.getPrintingPolicy());
+ Policy.UseEnumerators = true;
+ unsigned Limit = Context.getDiagnostics().getConstexprValueSizeLimit();
+ if (Limit) {
+ size_limited_ostream OSS(OS, Limit);
+ V.printPretty(OSS, Policy, T, &Context);
+ } else
+ V.printPretty(OS, Policy, T, &Context);
+ } break;
+
+ case APValue::ValueKind::Struct: {
+ llvm::raw_svector_ostream OS(Str);
+ const auto *RT = T->getAsStructureType();
+ if (RT->hasUnnamedOrLocalType()) {
+ OS << '(';
+ // e.g. `(unnamed struct at ...)`, unless...
+ if (const auto *Defn = RT->getDecl()->getDefinition()) {
+ if (const NamedDecl *ND =
+ dyn_cast_if_present<NamedDecl>(Defn->getNextDeclInContext())) {
+ // ... it's part of a declaration, then use `(decltype(...))`
+ OS << "decltype(";
+ ND->printQualifiedName(OS);
+ OS << ")";
+ } else
+ Defn->printQualifiedName(OS);
+ }
+ OS << ')';
+ } else if (T.hasQualifiers()) {
+ OS << '(' << T << ')';
+ } else {
+ PrintingPolicy TyPolicy(Context.getPrintingPolicy());
+ TyPolicy.SuppressUnwrittenScope = true;
+ T.print(OS, TyPolicy);
+ }
----------------
cor3ntin wrote:
Why are these two cases so different?
https://github.com/llvm/llvm-project/pull/74852
More information about the cfe-commits
mailing list