aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorMatheus Izvekov <mizvekov@gmail.com>2021-10-11 18:15:36 +0200
committerMatheus Izvekov <mizvekov@gmail.com>2022-07-15 04:16:55 +0200
commit7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f (patch)
treeeadc0bb2ce4c694d22f9813a3cf21d6a9b028bb6 /clang/unittests
parent190518da4b6b3f4cfb4081b7e110d8a3b9080cc5 (diff)
downloadllvm-7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f.zip
llvm-7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f.tar.gz
llvm-7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f.tar.bz2
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which goes against the intent that we should produce an AST which retains enough details to recover how things are written. The lack of this sugar is incompatible with the intent of the type printer default policy, which is to print types as written, but to fall back and print them fully qualified when they are desugared. An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still requires pointer alignment due to pre-existing bug in the TypeLoc buffer handling. --- Troubleshooting list to deal with any breakage seen with this patch: 1) The most likely effect one would see by this patch is a change in how a type is printed. The type printer will, by design and default, print types as written. There are customization options there, but not that many, and they mainly apply to how to print a type that we somehow failed to track how it was written. This patch fixes a problem where we failed to distinguish between a type that was written without any elaborated-type qualifiers, such as a 'struct'/'class' tags and name spacifiers such as 'std::', and one that has been stripped of any 'metadata' that identifies such, the so called canonical types. Example: ``` namespace foo { struct A {}; A a; }; ``` If one were to print the type of `foo::a`, prior to this patch, this would result in `foo::A`. This is how the type printer would have, by default, printed the canonical type of A as well. As soon as you add any name qualifiers to A, the type printer would suddenly start accurately printing the type as written. This patch will make it print it accurately even when written without qualifiers, so we will just print `A` for the initial example, as the user did not really write that `foo::` namespace qualifier. 2) This patch could expose a bug in some AST matcher. Matching types is harder to get right when there is sugar involved. For example, if you want to match a type against being a pointer to some type A, then you have to account for getting a type that is sugar for a pointer to A, or being a pointer to sugar to A, or both! Usually you would get the second part wrong, and this would work for a very simple test where you don't use any name qualifiers, but you would discover is broken when you do. The usual fix is to either use the matcher which strips sugar, which is annoying to use as for example if you match an N level pointer, you have to put N+1 such matchers in there, beginning to end and between all those levels. But in a lot of cases, if the property you want to match is present in the canonical type, it's easier and faster to just match on that... This goes with what is said in 1), if you want to match against the name of a type, and you want the name string to be something stable, perhaps matching on the name of the canonical type is the better choice. 3) This patch could exposed a bug in how you get the source range of some TypeLoc. For some reason, a lot of code is using getLocalSourceRange(), which only looks at the given TypeLoc node. This patch introduces a new, and more common TypeLoc node which contains no source locations on itself. This is not an inovation here, and some other, more rare TypeLoc nodes could also have this property, but if you use getLocalSourceRange on them, it's not going to return any valid locations, because it doesn't have any. The right fix here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive into the inner TypeLoc to get the source range if it doesn't find it on the top level one. You can use getLocalSourceRange if you are really into micro-optimizations and you have some outside knowledge that the TypeLocs you are dealing with will always include some source location. 4) Exposed a bug somewhere in the use of the normal clang type class API, where you have some type, you want to see if that type is some particular kind, you try a `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match. Again, like 2), this would usually have been tested poorly with some simple tests with no qualifications, and would have been broken had there been any other kind of type sugar, be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType. The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper into the type. Or use `getAsAdjusted` when dealing with TypeLocs. For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast. 5) It could be a bug in this patch perhaps. Let me know if you need any help! Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D112374
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/AST/ASTImporterTest.cpp64
-rw-r--r--clang/unittests/AST/ASTTraverserTest.cpp6
-rw-r--r--clang/unittests/AST/TypePrinterTest.cpp2
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp28
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp27
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp112
-rw-r--r--clang/unittests/Introspection/IntrospectionTest.cpp194
-rw-r--r--clang/unittests/Sema/CodeCompleteTest.cpp6
-rw-r--r--clang/unittests/StaticAnalyzer/SValTest.cpp5
-rw-r--r--clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp3
-rw-r--r--clang/unittests/Tooling/QualTypeNamesTest.cpp14
-rw-r--r--clang/unittests/Tooling/RecursiveASTVisitorTestTypeLocVisitor.cpp2
-rw-r--r--clang/unittests/Tooling/StencilTest.cpp5
13 files changed, 285 insertions, 183 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index d0edbcb..62d8d82 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -420,14 +420,15 @@ TEST_P(ImportExpr, ImportParenListExpr) {
"typedef dummy<int> declToImport;"
"template class dummy<int>;",
Lang_CXX03, "", Lang_CXX03, Verifier,
- typedefDecl(hasType(templateSpecializationType(
+ typedefDecl(hasType(elaboratedType(namesType(templateSpecializationType(
hasDeclaration(classTemplateSpecializationDecl(hasSpecializedTemplate(
- classTemplateDecl(hasTemplateDecl(cxxRecordDecl(hasMethod(allOf(
- hasName("f"),
- hasBody(compoundStmt(has(declStmt(hasSingleDecl(
- varDecl(hasInitializer(parenListExpr(has(unaryOperator(
- hasOperatorName("*"),
- hasUnaryOperand(cxxThisExpr())))))))))))))))))))))));
+ classTemplateDecl(hasTemplateDecl(cxxRecordDecl(hasMethod(
+ allOf(hasName("f"),
+ hasBody(compoundStmt(has(declStmt(hasSingleDecl(varDecl(
+ hasInitializer(parenListExpr(has(unaryOperator(
+ hasOperatorName("*"),
+ hasUnaryOperand(
+ cxxThisExpr())))))))))))))))))))))))));
}
TEST_P(ImportExpr, ImportSwitch) {
@@ -514,20 +515,19 @@ TEST_P(ImportExpr, ImportPredefinedExpr) {
TEST_P(ImportExpr, ImportInitListExpr) {
MatchVerifier<Decl> Verifier;
- testImport(
- "void declToImport() {"
- " struct point { double x; double y; };"
- " point ptarray[10] = { [2].y = 1.0, [2].x = 2.0,"
- " [0].x = 1.0 }; }",
- Lang_CXX03, "", Lang_CXX03, Verifier,
- functionDecl(hasDescendant(initListExpr(
- has(cxxConstructExpr(requiresZeroInitialization())),
- has(initListExpr(
- hasType(asString("struct point")), has(floatLiteral(equals(1.0))),
- has(implicitValueInitExpr(hasType(asString("double")))))),
- has(initListExpr(hasType(asString("struct point")),
- has(floatLiteral(equals(2.0))),
- has(floatLiteral(equals(1.0)))))))));
+ testImport("void declToImport() {"
+ " struct point { double x; double y; };"
+ " point ptarray[10] = { [2].y = 1.0, [2].x = 2.0,"
+ " [0].x = 1.0 }; }",
+ Lang_CXX03, "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(initListExpr(
+ has(cxxConstructExpr(requiresZeroInitialization())),
+ has(initListExpr(
+ hasType(asString("point")), has(floatLiteral(equals(1.0))),
+ has(implicitValueInitExpr(hasType(asString("double")))))),
+ has(initListExpr(hasType(asString("point")),
+ has(floatLiteral(equals(2.0))),
+ has(floatLiteral(equals(1.0)))))))));
}
const internal::VariadicDynCastAllOfMatcher<Expr, CXXDefaultInitExpr>
@@ -582,8 +582,8 @@ TEST_P(ImportType, ImportUsingType) {
testImport("struct C {};"
"void declToImport() { using ::C; new C{}; }",
Lang_CXX11, "", Lang_CXX11, Verifier,
- functionDecl(hasDescendant(
- cxxNewExpr(hasType(pointerType(pointee(usingType())))))));
+ functionDecl(hasDescendant(cxxNewExpr(hasType(pointerType(
+ pointee(elaboratedType(namesType(usingType())))))))));
}
TEST_P(ImportDecl, ImportFunctionTemplateDecl) {
@@ -680,7 +680,8 @@ TEST_P(ImportType, ImportDeducedTemplateSpecialization) {
"class C { public: C(T); };"
"C declToImport(123);",
Lang_CXX17, "", Lang_CXX17, Verifier,
- varDecl(hasType(deducedTemplateSpecializationType())));
+ varDecl(hasType(elaboratedType(
+ namesType(deducedTemplateSpecializationType())))));
}
const internal::VariadicDynCastAllOfMatcher<Stmt, SizeOfPackExpr>
@@ -897,9 +898,9 @@ TEST_P(ImportDecl, ImportUsingTemplate) {
"void declToImport() {"
"using ns::S; X<S> xi; }",
Lang_CXX11, "", Lang_CXX11, Verifier,
- functionDecl(
- hasDescendant(varDecl(hasTypeLoc(templateSpecializationTypeLoc(
- hasAnyTemplateArgumentLoc(templateArgumentLoc())))))));
+ functionDecl(hasDescendant(varDecl(hasTypeLoc(elaboratedTypeLoc(
+ hasNamedTypeLoc(templateSpecializationTypeLoc(
+ hasAnyTemplateArgumentLoc(templateArgumentLoc())))))))));
}
TEST_P(ImportDecl, ImportUsingEnumDecl) {
@@ -920,8 +921,9 @@ TEST_P(ImportDecl, ImportUsingPackDecl) {
"template<typename ...T> struct C : T... { using T::operator()...; };"
"C<A, B> declToImport;",
Lang_CXX20, "", Lang_CXX20, Verifier,
- varDecl(hasType(templateSpecializationType(hasDeclaration(
- classTemplateSpecializationDecl(hasDescendant(usingPackDecl())))))));
+ varDecl(hasType(elaboratedType(namesType(templateSpecializationType(
+ hasDeclaration(classTemplateSpecializationDecl(
+ hasDescendant(usingPackDecl())))))))));
}
/// \brief Matches shadow declarations introduced into a scope by a
@@ -7144,7 +7146,7 @@ TEST_P(CTAD, DeductionGuideShouldReferToANonLocalTypedef) {
ParmVarDecl *Param = Guide->getParamDecl(0);
// The type of the first param (which is a typedef) should match the typedef
// in the global scope.
- EXPECT_EQ(Param->getType()->castAs<TypedefType>()->getDecl(), Typedef);
+ EXPECT_EQ(Param->getType()->getAs<TypedefType>()->getDecl(), Typedef);
}
TEST_P(CTAD, DeductionGuideShouldReferToANonLocalTypedefInParamPtr) {
@@ -7185,7 +7187,7 @@ TEST_P(CTAD, DeductionGuideShouldCopyALocalTypedef) {
auto *Typedef = FirstDeclMatcher<TypedefNameDecl>().match(
TU, typedefNameDecl(hasName("U")));
ParmVarDecl *Param = Guide->getParamDecl(0);
- EXPECT_NE(Param->getType()->castAs<TypedefType>()->getDecl(), Typedef);
+ EXPECT_NE(Param->getType()->getAs<TypedefType>()->getDecl(), Typedef);
}
INSTANTIATE_TEST_SUITE_P(ParameterizedTests, CTAD,
diff --git a/clang/unittests/AST/ASTTraverserTest.cpp b/clang/unittests/AST/ASTTraverserTest.cpp
index 3553c30..f51d50a 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -1211,9 +1211,9 @@ void decompTuple()
CXXRecordDecl 'Record'
|-CXXRecordDecl 'Record'
|-CXXConstructorDecl 'Record'
-| |-CXXCtorInitializer 'struct Simple'
+| |-CXXCtorInitializer 'Simple'
| | `-CXXConstructExpr
-| |-CXXCtorInitializer 'struct Other'
+| |-CXXCtorInitializer 'Other'
| | `-CXXConstructExpr
| |-CXXCtorInitializer 'm_i'
| | `-IntegerLiteral
@@ -1234,7 +1234,7 @@ CXXRecordDecl 'Record'
R"cpp(
CXXRecordDecl 'Record'
|-CXXConstructorDecl 'Record'
-| |-CXXCtorInitializer 'struct Simple'
+| |-CXXCtorInitializer 'Simple'
| | `-CXXConstructExpr
| |-CXXCtorInitializer 'm_i'
| | `-IntegerLiteral
diff --git a/clang/unittests/AST/TypePrinterTest.cpp b/clang/unittests/AST/TypePrinterTest.cpp
index 12801a7..322a1b8 100644
--- a/clang/unittests/AST/TypePrinterTest.cpp
+++ b/clang/unittests/AST/TypePrinterTest.cpp
@@ -60,7 +60,7 @@ TEST(TypePrinter, TemplateId) {
[](PrintingPolicy &Policy) { Policy.FullyQualifiedName = false; }));
ASSERT_TRUE(PrintedTypeMatches(
- Code, {}, Matcher, "const N::Type<T> &",
+ Code, {}, Matcher, "const Type<T> &",
[](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
}
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 7811402..752a736 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1348,15 +1348,14 @@ TEST_P(ASTMatchersTest, HasType_MatchesAsString) {
EXPECT_TRUE(
matches("class Y { public: void x(); }; void z() {Y* y; y->x(); }",
- cxxMemberCallExpr(on(hasType(asString("class Y *"))))));
+ cxxMemberCallExpr(on(hasType(asString("Y *"))))));
EXPECT_TRUE(
matches("class X { void x(int x) {} };",
cxxMethodDecl(hasParameter(0, hasType(asString("int"))))));
EXPECT_TRUE(matches("namespace ns { struct A {}; } struct B { ns::A a; };",
fieldDecl(hasType(asString("ns::A")))));
- EXPECT_TRUE(
- matches("namespace { struct A {}; } struct B { A a; };",
- fieldDecl(hasType(asString("struct (anonymous namespace)::A")))));
+ EXPECT_TRUE(matches("namespace { struct A {}; } struct B { A a; };",
+ fieldDecl(hasType(asString("A")))));
}
TEST_P(ASTMatchersTest, HasOverloadedOperatorName) {
@@ -2142,9 +2141,10 @@ TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
EXPECT_TRUE(matches(
Code,
cxxDependentScopeMemberExpr(
- hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
- hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
- has(cxxMethodDecl(hasName("mem")).bind("templMem")))))))))),
+ hasObjectExpression(declRefExpr(hasType(elaboratedType(namesType(
+ templateSpecializationType(hasDeclaration(classTemplateDecl(
+ has(cxxRecordDecl(has(cxxMethodDecl(hasName("mem"))
+ .bind("templMem")))))))))))),
memberHasSameNameAsBoundNode("templMem"))));
EXPECT_TRUE(
@@ -2162,9 +2162,10 @@ TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
EXPECT_TRUE(matches(
Code,
cxxDependentScopeMemberExpr(
- hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
- hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
- has(fieldDecl(hasName("mem")).bind("templMem")))))))))),
+ hasObjectExpression(declRefExpr(
+ hasType(elaboratedType(namesType(templateSpecializationType(
+ hasDeclaration(classTemplateDecl(has(cxxRecordDecl(has(
+ fieldDecl(hasName("mem")).bind("templMem")))))))))))),
memberHasSameNameAsBoundNode("templMem"))));
}
@@ -2179,9 +2180,10 @@ TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
EXPECT_TRUE(matches(
Code,
cxxDependentScopeMemberExpr(
- hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
- hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
- has(varDecl(hasName("mem")).bind("templMem")))))))))),
+ hasObjectExpression(declRefExpr(
+ hasType(elaboratedType(namesType(templateSpecializationType(
+ hasDeclaration(classTemplateDecl(has(cxxRecordDecl(
+ has(varDecl(hasName("mem")).bind("templMem")))))))))))),
memberHasSameNameAsBoundNode("templMem"))));
}
{
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 195ac67..d11609c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1809,7 +1809,8 @@ TEST_P(ASTMatchersTest, PointerType_MatchesPointersToConstTypes) {
TEST_P(ASTMatchersTest, TypedefType) {
EXPECT_TRUE(matches("typedef int X; X a;",
- varDecl(hasName("a"), hasType(typedefType()))));
+ varDecl(hasName("a"), hasType(elaboratedType(
+ namesType(typedefType()))))));
}
TEST_P(ASTMatchersTest, TemplateSpecializationType) {
@@ -1858,7 +1859,7 @@ TEST_P(ASTMatchersTest, ElaboratedType) {
"N::M::D d;",
elaboratedType()));
EXPECT_TRUE(matches("class C {} c;", elaboratedType()));
- EXPECT_TRUE(notMatches("class C {}; C c;", elaboratedType()));
+ EXPECT_TRUE(matches("class C {}; C c;", elaboratedType()));
}
TEST_P(ASTMatchersTest, SubstTemplateTypeParmType) {
@@ -2179,7 +2180,8 @@ TEST_P(ASTMatchersTest,
}
EXPECT_TRUE(matches(
"template <typename T> class C {}; C<char> var;",
- varDecl(hasName("var"), hasTypeLoc(templateSpecializationTypeLoc()))));
+ varDecl(hasName("var"), hasTypeLoc(elaboratedTypeLoc(hasNamedTypeLoc(
+ templateSpecializationTypeLoc()))))));
}
TEST_P(
@@ -2218,13 +2220,12 @@ TEST_P(ASTMatchersTest,
}
TEST_P(ASTMatchersTest,
- ElaboratedTypeLocTest_DoesNotBindToNonElaboratedObjectDeclaration) {
+ ElaboratedTypeLocTest_BindsToBareElaboratedObjectDeclaration) {
if (!GetParam().isCXX()) {
return;
}
- EXPECT_TRUE(
- notMatches("class C {}; C c;",
- varDecl(hasName("c"), hasTypeLoc(elaboratedTypeLoc()))));
+ EXPECT_TRUE(matches("class C {}; C c;",
+ varDecl(hasName("c"), hasTypeLoc(elaboratedTypeLoc()))));
}
TEST_P(
@@ -2233,19 +2234,17 @@ TEST_P(
if (!GetParam().isCXX()) {
return;
}
- EXPECT_TRUE(
- notMatches("namespace N { class D {}; } using N::D; D d;",
- varDecl(hasName("d"), hasTypeLoc(elaboratedTypeLoc()))));
+ EXPECT_TRUE(matches("namespace N { class D {}; } using N::D; D d;",
+ varDecl(hasName("d"), hasTypeLoc(elaboratedTypeLoc()))));
}
TEST_P(ASTMatchersTest,
- ElaboratedTypeLocTest_DoesNotBindToNonElaboratedStructDeclaration) {
+ ElaboratedTypeLocTest_BindsToBareElaboratedStructDeclaration) {
if (!GetParam().isCXX()) {
return;
}
- EXPECT_TRUE(
- notMatches("struct s {}; s ss;",
- varDecl(hasName("ss"), hasTypeLoc(elaboratedTypeLoc()))));
+ EXPECT_TRUE(matches("struct s {}; s ss;",
+ varDecl(hasName("ss"), hasTypeLoc(elaboratedTypeLoc()))));
}
TEST_P(ASTMatchersTest, LambdaCaptureTest) {
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 8b3881a..11f293f 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -187,13 +187,15 @@ TEST(TypeMatcher, MatchesDeclTypes) {
parmVarDecl(hasType(namedDecl(hasName("T"))))));
// InjectedClassNameType
EXPECT_TRUE(matches("template <typename T> struct S {"
- " void f(S s);"
- "};",
- parmVarDecl(hasType(injectedClassNameType()))));
+ " void f(S s);"
+ "};",
+ parmVarDecl(hasType(elaboratedType(
+ namesType(injectedClassNameType()))))));
EXPECT_TRUE(notMatches("template <typename T> struct S {"
- " void g(S<T> s);"
- "};",
- parmVarDecl(hasType(injectedClassNameType()))));
+ " void g(S<T> s);"
+ "};",
+ parmVarDecl(hasType(elaboratedType(
+ namesType(injectedClassNameType()))))));
// InjectedClassNameType -> CXXRecordDecl
EXPECT_TRUE(matches("template <typename T> struct S {"
" void f(S s);"
@@ -243,24 +245,28 @@ TEST(HasDeclaration, ElaboratedType) {
}
TEST(HasDeclaration, HasDeclarationOfTypeWithDecl) {
- EXPECT_TRUE(matches("typedef int X; X a;",
- varDecl(hasName("a"),
- hasType(typedefType(hasDeclaration(decl()))))));
+ EXPECT_TRUE(matches(
+ "typedef int X; X a;",
+ varDecl(hasName("a"), hasType(elaboratedType(namesType(
+ typedefType(hasDeclaration(decl()))))))));
// FIXME: Add tests for other types with getDecl() (e.g. RecordType)
}
TEST(HasDeclaration, HasDeclarationOfTemplateSpecializationType) {
- EXPECT_TRUE(matches("template <typename T> class A {}; A<int> a;",
- varDecl(hasType(templateSpecializationType(
- hasDeclaration(namedDecl(hasName("A"))))))));
- EXPECT_TRUE(matches("template <typename T> class A {};"
- "template <typename T> class B { A<T> a; };",
- fieldDecl(hasType(templateSpecializationType(
- hasDeclaration(namedDecl(hasName("A"))))))));
- EXPECT_TRUE(matches("template <typename T> class A {}; A<int> a;",
- varDecl(hasType(templateSpecializationType(
- hasDeclaration(cxxRecordDecl()))))));
+ EXPECT_TRUE(matches(
+ "template <typename T> class A {}; A<int> a;",
+ varDecl(hasType(elaboratedType(namesType(templateSpecializationType(
+ hasDeclaration(namedDecl(hasName("A"))))))))));
+ EXPECT_TRUE(matches(
+ "template <typename T> class A {};"
+ "template <typename T> class B { A<T> a; };",
+ fieldDecl(hasType(elaboratedType(namesType(templateSpecializationType(
+ hasDeclaration(namedDecl(hasName("A"))))))))));
+ EXPECT_TRUE(matches(
+ "template <typename T> class A {}; A<int> a;",
+ varDecl(hasType(elaboratedType(namesType(
+ templateSpecializationType(hasDeclaration(cxxRecordDecl()))))))));
}
TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {
@@ -270,9 +276,10 @@ TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {
}
TEST(HasDeclaration, HasDeclarationOfTypeAlias) {
- EXPECT_TRUE(matches("template <typename T> using C = T; C<int> c;",
- varDecl(hasType(templateSpecializationType(
- hasDeclaration(typeAliasTemplateDecl()))))));
+ EXPECT_TRUE(matches(
+ "template <typename T> using C = T; C<int> c;",
+ varDecl(hasType(elaboratedType(namesType(templateSpecializationType(
+ hasDeclaration(typeAliasTemplateDecl()))))))));
}
TEST(HasUnqualifiedDesugaredType, DesugarsUsing) {
@@ -393,9 +400,9 @@ TEST(HasTypeLoc, MatchesCXXBaseSpecifierAndCtorInitializer) {
)cpp";
EXPECT_TRUE(matches(
- code, cxxRecordDecl(hasAnyBase(hasTypeLoc(loc(asString("class Foo")))))));
- EXPECT_TRUE(matches(
- code, cxxCtorInitializer(hasTypeLoc(loc(asString("class Foo"))))));
+ code, cxxRecordDecl(hasAnyBase(hasTypeLoc(loc(asString("Foo")))))));
+ EXPECT_TRUE(
+ matches(code, cxxCtorInitializer(hasTypeLoc(loc(asString("Foo"))))));
}
TEST(HasTypeLoc, MatchesCXXFunctionalCastExpr) {
@@ -407,13 +414,13 @@ TEST(HasTypeLoc, MatchesCXXNewExpr) {
EXPECT_TRUE(matches("auto* x = new int(3);",
cxxNewExpr(hasTypeLoc(loc(asString("int"))))));
EXPECT_TRUE(matches("class Foo{}; auto* x = new Foo();",
- cxxNewExpr(hasTypeLoc(loc(asString("class Foo"))))));
+ cxxNewExpr(hasTypeLoc(loc(asString("Foo"))))));
}
TEST(HasTypeLoc, MatchesCXXTemporaryObjectExpr) {
EXPECT_TRUE(
matches("struct Foo { Foo(int, int); }; auto x = Foo(1, 2);",
- cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("struct Foo"))))));
+ cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("Foo"))))));
}
TEST(HasTypeLoc, MatchesCXXUnresolvedConstructExpr) {
@@ -439,9 +446,8 @@ TEST(HasTypeLoc, MatchesDeclaratorDecl) {
varDecl(hasName("x"), hasTypeLoc(loc(asString("int"))))));
EXPECT_TRUE(matches("int x(3);",
varDecl(hasName("x"), hasTypeLoc(loc(asString("int"))))));
- EXPECT_TRUE(
- matches("struct Foo { Foo(int, int); }; Foo x(1, 2);",
- varDecl(hasName("x"), hasTypeLoc(loc(asString("struct Foo"))))));
+ EXPECT_TRUE(matches("struct Foo { Foo(int, int); }; Foo x(1, 2);",
+ varDecl(hasName("x"), hasTypeLoc(loc(asString("Foo"))))));
// Make sure we don't crash on implicit constructors.
EXPECT_TRUE(notMatches("class X {}; X x;",
@@ -6098,19 +6104,21 @@ TEST(HasReferentLoc, DoesNotBindToParameterWithoutIntReferenceTypeLoc) {
}
TEST(HasAnyTemplateArgumentLoc, BindsToSpecializationWithIntArgument) {
- EXPECT_TRUE(
- matches("template<typename T> class A {}; A<int> a;",
- varDecl(hasName("a"), hasTypeLoc(templateSpecializationTypeLoc(
- hasAnyTemplateArgumentLoc(hasTypeLoc(
- loc(asString("int")))))))));
+ EXPECT_TRUE(matches(
+ "template<typename T> class A {}; A<int> a;",
+ varDecl(hasName("a"),
+ hasTypeLoc(elaboratedTypeLoc(hasNamedTypeLoc(
+ templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(
+ hasTypeLoc(loc(asString("int")))))))))));
}
TEST(HasAnyTemplateArgumentLoc, BindsToSpecializationWithDoubleArgument) {
- EXPECT_TRUE(
- matches("template<typename T> class A {}; A<double> a;",
- varDecl(hasName("a"), hasTypeLoc(templateSpecializationTypeLoc(
- hasAnyTemplateArgumentLoc(hasTypeLoc(
- loc(asString("double")))))))));
+ EXPECT_TRUE(matches(
+ "template<typename T> class A {}; A<double> a;",
+ varDecl(hasName("a"),
+ hasTypeLoc(elaboratedTypeLoc(hasNamedTypeLoc(
+ templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(
+ hasTypeLoc(loc(asString("double")))))))))));
}
TEST(HasAnyTemplateArgumentLoc, BindsToExplicitSpecializationWithIntArgument) {
@@ -6170,19 +6178,21 @@ TEST(HasAnyTemplateArgumentLoc,
}
TEST(HasTemplateArgumentLoc, BindsToSpecializationWithIntArgument) {
- EXPECT_TRUE(matches(
- "template<typename T> class A {}; A<int> a;",
- varDecl(hasName("a"),
- hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(
- 0, hasTypeLoc(loc(asString("int")))))))));
+ EXPECT_TRUE(
+ matches("template<typename T> class A {}; A<int> a;",
+ varDecl(hasName("a"),
+ hasTypeLoc(elaboratedTypeLoc(hasNamedTypeLoc(
+ templateSpecializationTypeLoc(hasTemplateArgumentLoc(
+ 0, hasTypeLoc(loc(asString("int")))))))))));
}
TEST(HasTemplateArgumentLoc, BindsToSpecializationWithDoubleArgument) {
- EXPECT_TRUE(matches(
- "template<typename T> class A {}; A<double> a;",
- varDecl(hasName("a"),
- hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(
- 0, hasTypeLoc(loc(asString("double")))))))));
+ EXPECT_TRUE(
+ matches("template<typename T> class A {}; A<double> a;",
+ varDecl(hasName("a"),
+ hasTypeLoc(elaboratedTypeLoc(hasNamedTypeLoc(
+ templateSpecializationTypeLoc(hasTemplateArgumentLoc(
+ 0, hasTypeLoc(loc(asString("double")))))))))));
}
TEST(HasTemplateArgumentLoc, BindsToExplicitSpecializationWithIntArgument) {
@@ -6320,7 +6330,7 @@ TEST(HasNamedTypeLoc, BindsToElaboratedObjectDeclaration) {
}
TEST(HasNamedTypeLoc, DoesNotBindToNonElaboratedObjectDeclaration) {
- EXPECT_TRUE(notMatches(
+ EXPECT_TRUE(matches(
R"(
template <typename T>
class C {};
diff --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp
index 69e4616..5f5b231 100644
--- a/clang/unittests/Introspection/IntrospectionTest.cpp
+++ b/clang/unittests/Introspection/IntrospectionTest.cpp
@@ -780,13 +780,23 @@ struct B : A {
EXPECT_THAT(
ExpectedLocations,
UnorderedElementsAre(
-STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getBeginLoc()),
STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
STRING_LOCATION_PAIR(CtorInit, getLParenLoc()),
STRING_LOCATION_PAIR(CtorInit, getRParenLoc()),
STRING_LOCATION_PAIR(CtorInit, getSourceLocation()),
-STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getEndLoc())
));
@@ -798,11 +808,17 @@ STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getEndLoc())
EXPECT_THAT(
ExpectedRanges,
UnorderedElementsAre(
- STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getLocalSourceRange()),
- STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getSourceRange()),
- STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getLocalSourceRange()),
- STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
- STRING_LOCATION_PAIR(CtorInit, getSourceRange())));
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getSourceRange())));
// clang-format on
}
@@ -882,26 +898,31 @@ struct C {
STRING_LOCATION_PAIR(CtorInit, getLParenLoc()),
STRING_LOCATION_PAIR(CtorInit, getRParenLoc()),
STRING_LOCATION_PAIR(CtorInit, getSourceLocation()),
-STRING_LOCATION_PAIR(CtorInit,
- getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
-STRING_LOCATION_PAIR(CtorInit,
- getTypeSourceInfo()->getTypeLoc().getEndLoc()),
-STRING_LOCATION_PAIR(CtorInit,
- getTypeSourceInfo()->getTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc())
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc())
));
// clang-format on
auto ExpectedRanges = FormatExpected<SourceRange>(Result.RangeAccessors);
+ // clang-format off
EXPECT_THAT(
ExpectedRanges,
UnorderedElementsAre(
- STRING_LOCATION_PAIR(CtorInit, getSourceRange()),
- STRING_LOCATION_PAIR(
- CtorInit,
- getTypeSourceInfo()->getTypeLoc().getLocalSourceRange()),
- STRING_LOCATION_PAIR(
- CtorInit, getTypeSourceInfo()->getTypeLoc().getSourceRange())));
+STRING_LOCATION_PAIR(CtorInit, getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange())
+ ));
+ // clang-format on
}
TEST(Introspection, SourceLocations_CXXCtorInitializer_pack) {
@@ -943,38 +964,57 @@ struct D : Templ<T...> {
EXPECT_EQ(
llvm::makeArrayRef(ExpectedLocations),
(ArrayRef<std::pair<std::string, SourceLocation>>{
-STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
-STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
-STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getBeginLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getEndLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getEllipsisLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getLParenLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getMemberLocation()),
STRING_LOCATION_STDPAIR(CtorInit, getRParenLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getSourceLocation()),
-STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
-STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
-STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
-STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getEndLoc())
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc())
}));
// clang-format on
auto ExpectedRanges = FormatExpected<SourceRange>(Result.RangeAccessors);
+ // clang-format off
EXPECT_THAT(
ExpectedRanges,
UnorderedElementsAre(
- STRING_LOCATION_PAIR(CtorInit,
- getBaseClassLoc().getLocalSourceRange()),
- STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getSourceRange()),
- STRING_LOCATION_PAIR(CtorInit, getSourceRange()),
- STRING_LOCATION_PAIR(
- CtorInit,
- getTypeSourceInfo()->getTypeLoc().getLocalSourceRange()),
- STRING_LOCATION_PAIR(
- CtorInit, getTypeSourceInfo()->getTypeLoc().getSourceRange())));
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getBaseClassLoc().getNextTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(CtorInit, getSourceRange())
+ ));
+ // clang-format on
}
TEST(Introspection, SourceLocations_CXXBaseSpecifier_plain) {
@@ -991,7 +1031,7 @@ class B : A {};
auto BoundNodes = ast_matchers::match(
decl(hasDescendant(cxxRecordDecl(hasDirectBase(
- cxxBaseSpecifier(hasType(asString("class A"))).bind("base"))))),
+ cxxBaseSpecifier(hasType(asString("A"))).bind("base"))))),
TU, Ctx);
EXPECT_EQ(BoundNodes.size(), 1u);
@@ -1007,11 +1047,16 @@ class B : A {};
EXPECT_THAT(ExpectedLocations,
UnorderedElementsAre(
STRING_LOCATION_PAIR(Base, getBaseTypeLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
STRING_LOCATION_PAIR(Base, getBeginLoc()),
-STRING_LOCATION_PAIR(Base, getEndLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getEndLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc())
+STRING_LOCATION_PAIR(Base, getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc())
));
// clang-format on
@@ -1019,9 +1064,12 @@ STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc())
// clang-format off
EXPECT_THAT(ExpectedRanges, UnorderedElementsAre(
-STRING_LOCATION_PAIR(Base, getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getLocalSourceRange())
+STRING_LOCATION_PAIR(Base, getSourceRange())
));
// clang-format on
}
@@ -1040,7 +1088,7 @@ class B : public A {};
auto BoundNodes = ast_matchers::match(
decl(hasDescendant(cxxRecordDecl(hasDirectBase(
- cxxBaseSpecifier(hasType(asString("class A"))).bind("base"))))),
+ cxxBaseSpecifier(hasType(asString("A"))).bind("base"))))),
TU, Ctx);
EXPECT_EQ(BoundNodes.size(), 1u);
@@ -1055,12 +1103,17 @@ class B : public A {};
// clang-format off
EXPECT_THAT(ExpectedLocations,
UnorderedElementsAre(
-STRING_LOCATION_PAIR(Base, getBaseTypeLoc()),
STRING_LOCATION_PAIR(Base, getBeginLoc()),
-STRING_LOCATION_PAIR(Base, getEndLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(Base, getBaseTypeLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getEndLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc())
+STRING_LOCATION_PAIR(Base, getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc())
));
// clang-format on
@@ -1069,7 +1122,10 @@ STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc())
// clang-format off
EXPECT_THAT(ExpectedRanges, UnorderedElementsAre(
STRING_LOCATION_PAIR(Base, getSourceRange()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getSourceRange())
));
// clang-format on
@@ -1090,7 +1146,7 @@ class C : virtual B, A {};
auto BoundNodes = ast_matchers::match(
decl(hasDescendant(cxxRecordDecl(hasDirectBase(
- cxxBaseSpecifier(hasType(asString("class A"))).bind("base"))))),
+ cxxBaseSpecifier(hasType(asString("A"))).bind("base"))))),
TU, Ctx);
EXPECT_EQ(BoundNodes.size(), 1u);
@@ -1106,11 +1162,16 @@ class C : virtual B, A {};
EXPECT_THAT(ExpectedLocations,
UnorderedElementsAre(
STRING_LOCATION_PAIR(Base, getBaseTypeLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
STRING_LOCATION_PAIR(Base, getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getEndLoc()),
STRING_LOCATION_PAIR(Base, getEndLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getEndLoc())
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc())
));
// clang-format on
@@ -1118,9 +1179,12 @@ STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getEndLoc())
// clang-format off
EXPECT_THAT(ExpectedRanges, UnorderedElementsAre(
-STRING_LOCATION_PAIR(Base, getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getLocalSourceRange())
+STRING_LOCATION_PAIR(Base, getSourceRange())
));
// clang-format on
}
@@ -1156,13 +1220,20 @@ class B : A<int, bool> {};
EXPECT_THAT(ExpectedLocations,
UnorderedElementsAre(
STRING_LOCATION_PAIR(Base, getBaseTypeLoc()),
-STRING_LOCATION_PAIR(Base, getBeginLoc()),
-STRING_LOCATION_PAIR(Base, getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getBeginLoc()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getBeginLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_PAIR(Base, getBeginLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getTemplateNameLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getEndLoc()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getEndLoc()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc())
+STRING_LOCATION_PAIR(Base, getEndLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getRAngleLoc())
));
// clang-format on
@@ -1170,9 +1241,12 @@ STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::Templa
// clang-format off
EXPECT_THAT(ExpectedRanges, UnorderedElementsAre(
-STRING_LOCATION_PAIR(Base, getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getLocalSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getAs<clang::ElaboratedTypeLoc>().getNamedTypeLoc().getSourceRange()),
+STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getNextTypeLoc().getSourceRange()),
STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getSourceRange()),
-STRING_LOCATION_PAIR(Base, getTypeSourceInfo()->getTypeLoc().getLocalSourceRange())
+STRING_LOCATION_PAIR(Base, getSourceRange())
));
// clang-format on
}
diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp
index dae0793..3385628 100644
--- a/clang/unittests/Sema/CodeCompleteTest.cpp
+++ b/clang/unittests/Sema/CodeCompleteTest.cpp
@@ -250,7 +250,7 @@ TEST(PreferredTypeTest, BinaryExpr) {
a | ^1; a & ^1;
}
)cpp";
- EXPECT_THAT(collectPreferredTypes(Code), Each("enum A"));
+ EXPECT_THAT(collectPreferredTypes(Code), Each("A"));
Code = R"cpp(
enum class A {};
@@ -260,7 +260,7 @@ TEST(PreferredTypeTest, BinaryExpr) {
a | ^a; a & ^a;
}
)cpp";
- EXPECT_THAT(collectPreferredTypes(Code), Each("enum A"));
+ EXPECT_THAT(collectPreferredTypes(Code), Each("A"));
// Binary shifts.
Code = R"cpp(
@@ -296,7 +296,7 @@ TEST(PreferredTypeTest, BinaryExpr) {
c = ^c; c += ^c; c -= ^c; c *= ^c; c /= ^c; c %= ^c;
}
)cpp";
- EXPECT_THAT(collectPreferredTypes(Code), Each("class Cls"));
+ EXPECT_THAT(collectPreferredTypes(Code), Each("Cls"));
Code = R"cpp(
class Cls {};
diff --git a/clang/unittests/StaticAnalyzer/SValTest.cpp b/clang/unittests/StaticAnalyzer/SValTest.cpp
index 55a0730..d8897b0 100644
--- a/clang/unittests/StaticAnalyzer/SValTest.cpp
+++ b/clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -319,7 +319,10 @@ void foo(int x) {
ASSERT_TRUE(LD.has_value());
auto LDT = LD->getType(Context);
ASSERT_FALSE(LDT.isNull());
- const auto *DRecordType = dyn_cast<RecordType>(LDT);
+ const auto *DElaboratedType = dyn_cast<ElaboratedType>(LDT);
+ ASSERT_NE(DElaboratedType, nullptr);
+ const auto *DRecordType =
+ dyn_cast<RecordType>(DElaboratedType->getNamedType());
ASSERT_NE(DRecordType, nullptr);
EXPECT_EQ("TestStruct", DRecordType->getDecl()->getName());
}
diff --git a/clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp b/clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
index eb0ee6c..6661b33 100644
--- a/clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
+++ b/clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
@@ -38,7 +38,8 @@ public:
const auto *RetReg = cast<TypedValueRegion>(RetVal->getAsRegion());
const Expr *OrigExpr = Call.getOriginExpr();
- ASSERT_EQ(OrigExpr->getType(), RetReg->getValueType());
+ ASSERT_EQ(OrigExpr->getType()->getCanonicalTypeInternal(),
+ RetReg->getValueType()->getCanonicalTypeInternal());
}
};
diff --git a/clang/unittests/Tooling/QualTypeNamesTest.cpp b/clang/unittests/Tooling/QualTypeNamesTest.cpp
index 336a27e..4e51560 100644
--- a/clang/unittests/Tooling/QualTypeNamesTest.cpp
+++ b/clang/unittests/Tooling/QualTypeNamesTest.cpp
@@ -33,7 +33,7 @@ struct TypeNameVisitor : TestVisitor<TypeNameVisitor> {
ADD_FAILURE() << "Typename::getFullyQualifiedName failed for "
<< VD->getQualifiedNameAsString() << std::endl
<< " Actual: " << ActualName << std::endl
- << " Exepcted: " << ExpectedName;
+ << " Expected: " << ExpectedName;
}
}
return true;
@@ -42,7 +42,7 @@ struct TypeNameVisitor : TestVisitor<TypeNameVisitor> {
// named namespaces inside anonymous namespaces
-TEST(QualTypeNameTest, getFullyQualifiedName) {
+TEST(QualTypeNameTest, Simple) {
TypeNameVisitor Visitor;
// Simple case to test the test framework itself.
Visitor.ExpectedQualTypeNames["CheckInt"] = "int";
@@ -170,7 +170,9 @@ TEST(QualTypeNameTest, getFullyQualifiedName) {
"};\n"
"EnumScopeClass::AnEnum AnEnumVar;\n",
TypeNameVisitor::Lang_CXX11);
+}
+TEST(QualTypeNameTest, Complex) {
TypeNameVisitor Complex;
Complex.ExpectedQualTypeNames["CheckTX"] = "B::TX";
Complex.runOver(
@@ -187,7 +189,9 @@ TEST(QualTypeNameTest, getFullyQualifiedName) {
" TX CheckTX;"
" struct A { typedef int X; };"
"}");
+}
+TEST(QualTypeNameTest, DoubleUsing) {
TypeNameVisitor DoubleUsing;
DoubleUsing.ExpectedQualTypeNames["direct"] = "a::A<0>";
DoubleUsing.ExpectedQualTypeNames["indirect"] = "b::B";
@@ -206,7 +210,9 @@ TEST(QualTypeNameTest, getFullyQualifiedName) {
B double_indirect;
}
)cpp");
+}
+TEST(QualTypeNameTest, GlobalNsPrefix) {
TypeNameVisitor GlobalNsPrefix;
GlobalNsPrefix.WithGlobalNsPrefix = true;
GlobalNsPrefix.ExpectedQualTypeNames["IntVal"] = "int";
@@ -244,7 +250,9 @@ TEST(QualTypeNameTest, getFullyQualifiedName) {
" }\n"
"}\n"
);
+}
+TEST(QualTypeNameTest, InlineNamespace) {
TypeNameVisitor InlineNamespace;
InlineNamespace.ExpectedQualTypeNames["c"] = "B::C";
InlineNamespace.runOver("inline namespace A {\n"
@@ -255,7 +263,9 @@ TEST(QualTypeNameTest, getFullyQualifiedName) {
"using namespace A::B;\n"
"C c;\n",
TypeNameVisitor::Lang_CXX11);
+}
+TEST(QualTypeNameTest, AnonStrucs) {
TypeNameVisitor AnonStrucs;
AnonStrucs.ExpectedQualTypeNames["a"] = "short";
AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTestTypeLocVisitor.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTestTypeLocVisitor.cpp
index 299e1b0..6c6670c 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTestTypeLocVisitor.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTestTypeLocVisitor.cpp
@@ -45,7 +45,7 @@ TEST(RecursiveASTVisitor, VisitsCXXBaseSpecifiersWithIncompleteInnerClass) {
TEST(RecursiveASTVisitor, VisitsCXXBaseSpecifiersOfSelfReferentialType) {
TypeLocVisitor Visitor;
- Visitor.ExpectMatch("X<class Y>", 2, 18);
+ Visitor.ExpectMatch("X<Y>", 2, 18, 2);
EXPECT_TRUE(Visitor.runOver(
"template<typename T> class X {};\n"
"class Y : public X<Y> {};"));
diff --git a/clang/unittests/Tooling/StencilTest.cpp b/clang/unittests/Tooling/StencilTest.cpp
index 1f49c1a..45dab15 100644
--- a/clang/unittests/Tooling/StencilTest.cpp
+++ b/clang/unittests/Tooling/StencilTest.cpp
@@ -43,6 +43,7 @@ static std::string wrapSnippet(StringRef ExtraPreface,
T& operator*() const;
};
}
+ template<class T> T desugar() { return T(); };
)cc";
return (Preface + ExtraPreface + "auto stencil_test_snippet = []{" +
StatementCode + "};")
@@ -545,7 +546,7 @@ TEST_F(StencilTest, DescribeQualifiedType) {
TEST_F(StencilTest, DescribeUnqualifiedType) {
std::string Snippet = "using N::C; C c; c;";
- std::string Expected = "N::C";
+ std::string Expected = "C";
auto StmtMatch =
matchStmt(Snippet, declRefExpr(hasType(qualType().bind("type"))));
ASSERT_TRUE(StmtMatch);
@@ -554,7 +555,7 @@ TEST_F(StencilTest, DescribeUnqualifiedType) {
}
TEST_F(StencilTest, DescribeAnonNamespaceType) {
- std::string Snippet = "AnonC c; c;";
+ std::string Snippet = "auto c = desugar<AnonC>(); c;";
std::string Expected = "(anonymous namespace)::AnonC";
auto StmtMatch =
matchStmt(Snippet, declRefExpr(hasType(qualType().bind("type"))));