r268988 - When forming a fully-qualified type name, put any qualifiers outside/before the
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon May 9 16:06:14 PDT 2016
Author: rsmith
Date: Mon May 9 18:06:14 2016
New Revision: 268988
URL: http://llvm.org/viewvc/llvm-project?rev=268988&view=rev
Log:
When forming a fully-qualified type name, put any qualifiers outside/before the
nested-name-specifier. Patch by Sterling Augustine!
Modified:
cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
Modified: cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp?rev=268988&r1=268987&r2=268988&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp (original)
+++ cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp Mon May 9 18:06:14 2016
@@ -383,10 +383,15 @@ QualType getFullyQualifiedType(QualType
}
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();
+ QT = QualType(QT.getTypePtr(), 0);
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
@@ -394,28 +399,21 @@ QualType getFullyQualifiedType(QualType
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);
- }
-
// In case of template specializations iterate over the arguments and
// fully qualify them as well.
if (isa<const TemplateSpecializationType>(QT.getTypePtr()) ||
isa<const RecordType>(QT.getTypePtr())) {
// We are asked to fully qualify and we have a Record Type (which
- // may pont to a template specialization) or Template
+ // may point 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 = QualType(TypePtr, 0);
}
if (Prefix || Keyword != ETK_None) {
QT = Ctx.getElaboratedType(Keyword, Prefix, QT);
- QT = Ctx.getQualifiedType(QT, PrefixQualifiers);
}
+ QT = Ctx.getQualifiedType(QT, PrefixQualifiers);
return QT;
}
Modified: cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp?rev=268988&r1=268987&r2=268988&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp Mon May 9 18:06:14 2016
@@ -88,6 +88,8 @@ TEST(QualTypeNameTest, getFullyQualified
"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 @@ TEST(QualTypeNameTest, getFullyQualified
" 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 @@ TEST(QualTypeNameTest, getFullyQualified
"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"
More information about the cfe-commits
mailing list