diff options
| author | Olivier Goffart <ogoffart@woboq.com> | 2016-06-16 21:40:06 +0000 |
|---|---|---|
| committer | Olivier Goffart <ogoffart@woboq.com> | 2016-06-16 21:40:06 +0000 |
| commit | f9e890cbf964ec2222693034d159c49a28f6f117 (patch) | |
| tree | d9b8baadf77a24c92e1ccce8b7905d0a48367ab6 /clang/unittests | |
| parent | 119dad63bc5bd5ed46d2be2556af148264f9f62f (diff) | |
| download | bcm5719-llvm-f9e890cbf964ec2222693034d159c49a28f6f117.tar.gz bcm5719-llvm-f9e890cbf964ec2222693034d159c49a28f6f117.zip | |
Fix a few issues while skipping function bodies
- In functions with try { } catch { }, only the try block would be
skipped, not the catch blocks
- The template functions would still be parsed.
- The initializers within a constructor would still be parsed.
- The inline functions within class would still be stored, only to be
discared later.
- Invalid code with try would assert (as in "int foo() try assert_here")
This attempt to do even less while skipping function bodies.
Differential Revision: http://reviews.llvm.org/D20821
llvm-svn: 272963
Diffstat (limited to 'clang/unittests')
| -rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index c4b174f183d..c0b8695e344 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -241,7 +241,7 @@ TEST(newFrontendActionFactory, InjectsSourceFileCallbacks) { struct SkipBodyConsumer : public clang::ASTConsumer { /// Skip the 'skipMe' function. bool shouldSkipFunctionBody(Decl *D) override { - FunctionDecl *F = dyn_cast<FunctionDecl>(D); + NamedDecl *F = dyn_cast<NamedDecl>(D); return F && F->getNameAsString() == "skipMe"; } }; @@ -255,10 +255,64 @@ struct SkipBodyAction : public clang::ASTFrontendAction { }; TEST(runToolOnCode, TestSkipFunctionBody) { + std::vector<std::string> Args = {"-std=c++11"}; + EXPECT_TRUE(runToolOnCode(new SkipBodyAction, "int skipMe() { an_error_here }")); EXPECT_FALSE(runToolOnCode(new SkipBodyAction, "int skipMeNot() { an_error_here }")); + + // Test constructors with initializers + EXPECT_TRUE(runToolOnCodeWithArgs( + new SkipBodyAction, + "struct skipMe { skipMe() : an_error() { more error } };", Args)); + EXPECT_TRUE(runToolOnCodeWithArgs( + new SkipBodyAction, "struct skipMe { skipMe(); };" + "skipMe::skipMe() : an_error([](){;}) { more error }", + Args)); + EXPECT_TRUE(runToolOnCodeWithArgs( + new SkipBodyAction, "struct skipMe { skipMe(); };" + "skipMe::skipMe() : an_error{[](){;}} { more error }", + Args)); + EXPECT_TRUE(runToolOnCodeWithArgs( + new SkipBodyAction, + "struct skipMe { skipMe(); };" + "skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }", + Args)); + EXPECT_TRUE(runToolOnCodeWithArgs( + new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };", + Args)); + + EXPECT_FALSE(runToolOnCodeWithArgs( + new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };", + Args)); + EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction, + "struct skipMeNot { skipMeNot(); };" + "skipMeNot::skipMeNot() : an_error() { }", + Args)); + + // Try/catch + EXPECT_TRUE(runToolOnCode( + new SkipBodyAction, + "void skipMe() try { an_error() } catch(error) { error };")); + EXPECT_TRUE(runToolOnCode( + new SkipBodyAction, + "struct S { void skipMe() try { an_error() } catch(error) { error } };")); + EXPECT_TRUE( + runToolOnCode(new SkipBodyAction, + "void skipMe() try { an_error() } catch(error) { error; }" + "catch(error) { error } catch (error) { }")); + EXPECT_FALSE(runToolOnCode( + new SkipBodyAction, + "void skipMe() try something;")); // don't crash while parsing + + // Template + EXPECT_TRUE(runToolOnCode( + new SkipBodyAction, "template<typename T> int skipMe() { an_error_here }" + "int x = skipMe<int>();")); + EXPECT_FALSE( + runToolOnCode(new SkipBodyAction, + "template<typename T> int skipMeNot() { an_error_here }")); } TEST(runToolOnCodeWithArgs, TestNoDepFile) { |

