[PATCH] D15443: Fix getLocEnd for function declarations with exception specification.
Adrian ZgorzaĆek via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 11 20:53:21 PST 2016
adek05 updated this revision to Diff 44598.
adek05 added a comment.
Adding testcases in unittest/AST/SourceLocationTest.cpp as suggested by @aaronballman
Interestingly, without my change tests for function declarations pass. Only member functions fail:
tools/clang/unittests/AST/ASTTests
...
[----------] 2 tests from FunctionDecl
[ RUN ] FunctionDecl.FunctionDeclWithThrowSpecification
[ OK ] FunctionDecl.FunctionDeclWithThrowSpecification (17 ms)
[ RUN ] FunctionDecl.FunctionDeclWithNoExceptSpecification
[ OK ] FunctionDecl.FunctionDeclWithNoExceptSpecification (10 ms)
[----------] 2 tests from FunctionDecl (27 ms total)
[----------] 2 tests from CXXMethodDecl
[ RUN ] CXXMethodDecl.CXXMethodDeclWithThrowSpecification
/Users/adek/llvm-git/tools/clang/unittests/AST/SourceLocationTest.cpp:569: Failure
Value of: Verifier.match( "class A {\n" "void f() throw();\n" "};\n", functionDecl())
Actual: false (Expected range <2:1-2:16>, found <input.cc:2:1-input.cc:2:17>)
Expected: true
[ FAILED ] CXXMethodDecl.CXXMethodDeclWithThrowSpecification (10 ms)
[ RUN ] CXXMethodDecl.CXXMethodDeclWithNoExceptSpecification
/Users/adek/llvm-git/tools/clang/unittests/AST/SourceLocationTest.cpp:580: Failure
Value of: Verifier.match( "class A {\n" "void f() noexcept(false);\n" "};\n", functionDecl(), Language::Lang_CXX11)
Actual: false (Expected range <2:1-2:24>, found <input.cc:2:1-input.cc:2:25>)
Expected: true
[ FAILED ] CXXMethodDecl.CXXMethodDeclWithNoExceptSpecification (10 ms)
[----------] 2 tests from CXXMethodDecl (20 ms total)
Not sure why would they take different codepaths, throw and noexcept are C++(11) specific. Is the code parsed as C++11 anyway for Verifiers?
http://reviews.llvm.org/D15443
Files:
lib/Parse/ParseDeclCXX.cpp
unittests/AST/SourceLocationTest.cpp
Index: unittests/AST/SourceLocationTest.cpp
===================================================================
--- unittests/AST/SourceLocationTest.cpp
+++ unittests/AST/SourceLocationTest.cpp
@@ -542,5 +542,43 @@
cxxConstructExpr(), Lang_OBJCXX));
}
+TEST(FunctionDecl, FunctionDeclWithThrowSpecification) {
+ RangeVerifier<FunctionDecl> Verifier;
+ Verifier.expectRange(1, 1, 1, 16);
+ EXPECT_TRUE(Verifier.match(
+ "void f() throw();\n",
+ functionDecl()));
+}
+
+TEST(FunctionDecl, FunctionDeclWithNoExceptSpecification) {
+ RangeVerifier<FunctionDecl> Verifier;
+ Verifier.expectRange(1, 1, 1, 24);
+ EXPECT_TRUE(Verifier.match(
+ "void f() noexcept(false);\n",
+ functionDecl(),
+ Language::Lang_CXX11));
+}
+
+TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {
+ RangeVerifier<FunctionDecl> Verifier;
+ Verifier.expectRange(2, 1, 2, 16);
+ EXPECT_TRUE(Verifier.match(
+ "class A {\n"
+ "void f() throw();\n"
+ "};\n",
+ functionDecl()));
+}
+
+TEST(CXXMethodDecl, CXXMethodDeclWithNoExceptSpecification) {
+ RangeVerifier<FunctionDecl> 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
Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -3358,7 +3358,8 @@
ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
/*StopAtSemi=*/true,
/*ConsumeFinalToken=*/true);
- SpecificationRange.setEnd(Tok.getLocation());
+ SpecificationRange.setEnd(ExceptionSpecTokens->back().getLocation());
+
return EST_Unparsed;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15443.44598.patch
Type: text/x-patch
Size: 1900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160112/6604dbdc/attachment.bin>
More information about the cfe-commits
mailing list