[PATCH] D20040: Treat qualifiers on elaborated types for qualtypenames appropriately.

Sterling Augustine via cfe-commits cfe-commits at lists.llvm.org
Mon May 9 14:31:48 PDT 2016


saugustine updated this revision to Diff 56634.
saugustine marked an inline comment as done.
saugustine added a comment.

- Handle elaborated types even more cleanly.


http://reviews.llvm.org/D20040

Files:
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===================================================================
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -88,6 +88,8 @@
       "Foo<X>::non_dependent_type";
   Visitor.ExpectedQualTypeNames["AnEnumVar"] = "EnumScopeClass::AnEnum";
   Visitor.ExpectedQualTypeNames["AliasTypeVal"] = "A::B::C::InnerAlias<int>";
+  Visitor.ExpectedQualTypeNames["CheckM"] = "const A::B::Class0 *";
+  Visitor.ExpectedQualTypeNames["CheckN"] = "const X *";
   Visitor.runOver(
       "int CheckInt;\n"
       "template <typename T>\n"
@@ -108,6 +110,7 @@
       "                  AnotherClass> CheckC);\n"
       "   void Function2(Template0<Template1<C::MyInt, AnotherClass>,\n"
       "                            Template0<int, long> > CheckD);\n"
+      "   void Function3(const B::Class0* CheckM);\n"
       "  }\n"
       "template<typename... Values> class Variadic {};\n"
       "Variadic<int, B::Template0<int, char>, "
@@ -123,6 +126,8 @@
       "void f() {\n"
       "  struct X {} CheckH;\n"
       "}\n"
+      "struct X;\n"
+      "void f(const ::X* CheckN) {}\n"
       "namespace {\n"
       "  class aClass {};\n"
       "   aClass CheckI;\n"
Index: lib/Tooling/Core/QualTypeNames.cpp
===================================================================
--- lib/Tooling/Core/QualTypeNames.cpp
+++ lib/Tooling/Core/QualTypeNames.cpp
@@ -383,22 +383,22 @@
   }
 
   NestedNameSpecifier *Prefix = nullptr;
-  Qualifiers PrefixQualifiers;
+  // Local qualifiers are attached to the QualType outside of the
+  // elaborated type.  Retrieve them before descending into the
+  // elaborated type.
+  Qualifiers PrefixQualifiers = QT.getLocalQualifiers();
   ElaboratedTypeKeyword Keyword = ETK_None;
   if (const auto *ETypeInput = dyn_cast<ElaboratedType>(QT.getTypePtr())) {
     QT = ETypeInput->getNamedType();
+    assert(!QT.hasLocalQualifiers());
     Keyword = ETypeInput->getKeyword();
   }
   // Create a nested name specifier if needed (i.e. if the decl context
   // is not the global scope.
   Prefix = createNestedNameSpecifierForScopeOf(Ctx, QT.getTypePtr(),
                                                true /*FullyQualified*/);
 
-  // move the qualifiers on the outer type (avoid 'std::const string'!)
-  if (Prefix) {
-    PrefixQualifiers = QT.getLocalQualifiers();
-    QT = QualType(QT.getTypePtr(), 0);
-  }
+  QT = QualType(QT.getTypePtr(), 0);
 
   // In case of template specializations iterate over the arguments and
   // fully qualify them as well.
@@ -408,14 +408,13 @@
     // may pont to a template specialization) or Template
     // Specialization Type. We need to fully qualify their arguments.
 
-    Qualifiers Quals = QT.getLocalQualifiers();
     const Type *TypePtr = getFullyQualifiedTemplateType(Ctx, QT.getTypePtr());
-    QT = Ctx.getQualifiedType(TypePtr, Quals);
+    QT = Ctx.getQualifiedType(TypePtr, Qualifiers());
   }
   if (Prefix || Keyword != ETK_None) {
     QT = Ctx.getElaboratedType(Keyword, Prefix, QT);
-    QT = Ctx.getQualifiedType(QT, PrefixQualifiers);
   }
+  QT = Ctx.getQualifiedType(QT, PrefixQualifiers);
   return QT;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20040.56634.patch
Type: text/x-patch
Size: 3187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160509/6e8aae9e/attachment.bin>


More information about the cfe-commits mailing list