From: Aaron Ballman Date: Tue, 12 Jan 2016 21:04:22 +0000 (+0000) Subject: Properly track the end location of an exception specification. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89dda3855cda574f355e6defa1d77bdae5053994;p=clang Properly track the end location of an exception specification. Patch by Adrian ZgorzaƂek git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257521 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index a4de9751f9..3f22ad4dda 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -3363,7 +3363,8 @@ Parser::tryParseExceptionSpecification(bool Delayed, ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens, /*StopAtSemi=*/true, /*ConsumeFinalToken=*/true); - SpecificationRange.setEnd(Tok.getLocation()); + SpecificationRange.setEnd(ExceptionSpecTokens->back().getLocation()); + return EST_Unparsed; } diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index 4c77def61b..9fae8d862a 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -542,5 +542,43 @@ TEST(ObjCMessageExpr, CXXConstructExprRange) { cxxConstructExpr(), Lang_OBJCXX)); } +TEST(FunctionDecl, FunctionDeclWithThrowSpecification) { + RangeVerifier Verifier; + Verifier.expectRange(1, 1, 1, 16); + EXPECT_TRUE(Verifier.match( + "void f() throw();\n", + functionDecl())); +} + +TEST(FunctionDecl, FunctionDeclWithNoExceptSpecification) { + RangeVerifier Verifier; + Verifier.expectRange(1, 1, 1, 24); + EXPECT_TRUE(Verifier.match( + "void f() noexcept(false);\n", + functionDecl(), + Language::Lang_CXX11)); +} + +TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) { + RangeVerifier Verifier; + Verifier.expectRange(2, 1, 2, 16); + EXPECT_TRUE(Verifier.match( + "class A {\n" + "void f() throw();\n" + "};\n", + functionDecl())); +} + +TEST(CXXMethodDecl, CXXMethodDeclWithNoExceptSpecification) { + RangeVerifier Verifier; + Verifier.expectRange(2, 1, 2, 24); + EXPECT_TRUE(Verifier.match( + "class A {\n" + "void f() noexcept(false);\n" + "};\n", + functionDecl(), + Language::Lang_CXX11)); +} + } // end namespace ast_matchers } // end namespace clang