[PATCH] D149272: [clang] Call printName to get name of Decl

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 12:26:14 PDT 2023


aaron.ballman added a comment.

Thank you for working on this! Please be sure to add a release note and test coverage for the changes.



================
Comment at: clang/lib/AST/DeclarationName.cpp:119-125
   if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) {
-    OS << *ClassRec->getDecl();
+    ClassRec->getDecl()->printName(OS, Policy);
     return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
     if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) {
+      InjTy->getDecl()->printName(OS, Policy);
----------------
This isn't the right way to go about this -- the diagnostic engine knows how to print a `NamedDecl` when given one, and that's what should be fixed. (We pass in a `NamedDecl` all over the place -- it's preferred to passing in a string.)

https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/AST/ASTDiagnostic.cpp#L460 is one place where that happens, and https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/Basic/Diagnostic.cpp#L1060 is another, so I'd start investigating from there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272



More information about the cfe-commits mailing list