[clang-tools-extra] r289816 - [change-namespace] fix a case references to templated using alias are qualified types.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 15 05:02:41 PST 2016
Author: ioeric
Date: Thu Dec 15 07:02:41 2016
New Revision: 289816
URL: http://llvm.org/viewvc/llvm-project?rev=289816&view=rev
Log:
[change-namespace] fix a case references to templated using alias are qualified types.
Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=289816&r1=289815&r2=289816&view=diff
==============================================================================
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Dec 15 07:02:41 2016
@@ -457,16 +457,18 @@ void ChangeNamespaceTool::run(
// This avoids fixing types with record types as qualifier, which is not
// filtered by matchers in some cases, e.g. the type is templated. We should
// handle the record type qualifier instead.
- if (TLoc->getTypeLocClass() == TypeLoc::Elaborated) {
+ TypeLoc Loc = *TLoc;
+ while (Loc.getTypeLocClass() == TypeLoc::Qualified)
+ Loc = Loc.getNextTypeLoc();
+ if (Loc.getTypeLocClass() == TypeLoc::Elaborated) {
NestedNameSpecifierLoc NestedNameSpecifier =
- TLoc->castAs<ElaboratedTypeLoc>().getQualifierLoc();
+ Loc.castAs<ElaboratedTypeLoc>().getQualifierLoc();
const Type *SpecifierType =
NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
if (SpecifierType && SpecifierType->isRecordType())
return;
}
- fixTypeLoc(Result, startLocationForType(*TLoc), endLocationForType(*TLoc),
- *TLoc);
+ fixTypeLoc(Result, startLocationForType(Loc), endLocationForType(Loc), Loc);
} else if (const auto *VarRef =
Result.Nodes.getNodeAs<DeclRefExpr>("var_ref")) {
const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var_decl");
Modified: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=289816&r1=289815&r2=289816&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Thu Dec 15 07:02:41 2016
@@ -1365,6 +1365,8 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
"public:\n"
" template<typename P>\n"
" using GG = some_ns::G<int, P>;\n"
+ "\n"
+ " struct Nested {};\n"
"};\n"
"class Derived : public Base {};\n"
"} // namespace na\n"
@@ -1372,6 +1374,10 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
"namespace nb {\n"
"void f() {\n"
" Derived::GG<float> g;\n"
+ " const Derived::GG<int> gg;\n"
+ " const Derived::GG<int>* gg_ptr;\n"
+ " struct Derived::Nested nested;\n"
+ " const struct Derived::Nested *nested_ptr;\n"
"}\n"
"} // namespace nb\n"
"} // namespace na\n";
@@ -1384,6 +1390,8 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
"public:\n"
" template<typename P>\n"
" using GG = some_ns::G<int, P>;\n"
+ "\n"
+ " struct Nested {};\n"
"};\n"
"class Derived : public Base {};\n"
"} // namespace na\n"
@@ -1392,6 +1400,10 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
"namespace nc {\n"
"void f() {\n"
" Derived::GG<float> g;\n"
+ " const Derived::GG<int> gg;\n"
+ " const Derived::GG<int>* gg_ptr;\n"
+ " struct Derived::Nested nested;\n"
+ " const struct Derived::Nested *nested_ptr;\n"
"}\n"
"} // namespace nc\n\n"
"} // namespace nb\n"
More information about the cfe-commits
mailing list