From 952eddef9aff85b1e92626e89baaf7a360e2ac85 Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 22 Dec 2013 00:07:40 +0000 Subject: Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3): https://llvm.org/svn/llvm-project/cfe/branches/release_34@197841 --- unittests/AST/SourceLocationTest.cpp | 111 +++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) (limited to 'unittests/AST/SourceLocationTest.cpp') diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index f6c0edc..29156bc 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -155,5 +155,116 @@ TEST(InitListExpr, VectorLiteralInitListParens) { "constant int2 i2 = (int2)(1, 2);", initListExpr(), Lang_OpenCL)); } +class TemplateAngleBracketLocRangeVerifier : public RangeVerifier { +protected: + virtual SourceRange getRange(const TypeLoc &Node) { + TemplateSpecializationTypeLoc T = + Node.getUnqualifiedLoc().castAs(); + assert(!T.isNull()); + return SourceRange(T.getLAngleLoc(), T.getRAngleLoc()); + } +}; + +TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) { + TemplateAngleBracketLocRangeVerifier Verifier; + Verifier.expectRange(2, 8, 2, 10); + EXPECT_TRUE(Verifier.match( + "template struct A {}; struct B{}; void f(\n" + "const A&);", + loc(templateSpecializationType()))); +} + +TEST(CXXNewExpr, TypeParenRange) { + RangeVerifier Verifier; + Verifier.expectRange(1, 10, 1, 18); + EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr())); +} + +class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier { +protected: + virtual SourceRange getRange(const TypeLoc &Node) { + UnaryTransformTypeLoc T = + Node.getUnqualifiedLoc().castAs(); + assert(!T.isNull()); + return SourceRange(T.getLParenLoc(), T.getRParenLoc()); + } +}; + +TEST(UnaryTransformTypeLoc, ParensRange) { + UnaryTransformTypeLocParensRangeVerifier Verifier; + Verifier.expectRange(3, 26, 3, 28); + EXPECT_TRUE(Verifier.match( + "template \n" + "struct S {\n" + "typedef __underlying_type(T) type;\n" + "};", + loc(unaryTransformType()))); +} + +TEST(CXXFunctionalCastExpr, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(2, 10, 2, 14); + EXPECT_TRUE(Verifier.match( + "int foo() {\n" + " return int{};\n" + "}", + functionalCastExpr(), Lang_CXX11)); +} + +TEST(CXXTemporaryObjectExpr, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(2, 6, 2, 12); + EXPECT_TRUE(Verifier.match( + "struct A { A(int, int); };\n" + "A a( A{0, 0} );", + temporaryObjectExpr(), Lang_CXX11)); +} + +TEST(CXXUnresolvedConstructExpr, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(3, 10, 3, 12); + std::vector Args; + Args.push_back("-fno-delayed-template-parsing"); + EXPECT_TRUE(Verifier.match( + "template \n" + "U foo() {\n" + " return U{};\n" + "}", + unresolvedConstructExpr(), Args, Lang_CXX11)); +} + +TEST(UsingDecl, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(2, 22, 2, 25); + EXPECT_TRUE(Verifier.match( + "class B { protected: int i; };\n" + "class D : public B { B::i; };", + usingDecl())); +} + +TEST(UnresolvedUsingValueDecl, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(3, 3, 3, 6); + EXPECT_TRUE(Verifier.match( + "template \n" + "class D : public B {\n" + " B::i;\n" + "};", + unresolvedUsingValueDecl())); +} + +TEST(FriendDecl, InstantiationSourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(4, 3, 4, 35); + EXPECT_TRUE(Verifier.match( + "template class S;\n" + "template void operator+(S x);\n" + "template struct S {\n" + " friend void operator+<>(S src);\n" + "};\n" + "void test(S s) { +s; }", + friendDecl(hasParent(recordDecl(isTemplateInstantiation()))))); +} + } // end namespace ast_matchers } // end namespace clang -- cgit v1.1