summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Sema/ExternalSemaSourceTest.cpp
diff options
context:
space:
mode:
authorKaelyn Uhrain <rikka@google.com>2013-08-12 22:11:14 +0000
committerKaelyn Uhrain <rikka@google.com>2013-08-12 22:11:14 +0000
commit2c351bbc25e952a1be7ddabaf955fcc634d3ed4d (patch)
tree311a70fffed3cfb44cc1e2cc37bad5e1d240a6dd /clang/unittests/Sema/ExternalSemaSourceTest.cpp
parent812a9ec9c2659efc917ec736a5d3a78aef30e172 (diff)
downloadbcm5719-llvm-2c351bbc25e952a1be7ddabaf955fcc634d3ed4d.tar.gz
bcm5719-llvm-2c351bbc25e952a1be7ddabaf955fcc634d3ed4d.zip
Add hooks to ExternalSemaSource for after-the-fact diagnosis of
incomplete types, courtesy of Luke Zarko. llvm-svn: 188212
Diffstat (limited to 'clang/unittests/Sema/ExternalSemaSourceTest.cpp')
-rw-r--r--clang/unittests/Sema/ExternalSemaSourceTest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/clang/unittests/Sema/ExternalSemaSourceTest.cpp b/clang/unittests/Sema/ExternalSemaSourceTest.cpp
index 8aa626c2df1..e27d0cd1e39 100644
--- a/clang/unittests/Sema/ExternalSemaSourceTest.cpp
+++ b/clang/unittests/Sema/ExternalSemaSourceTest.cpp
@@ -24,6 +24,21 @@ using namespace clang::tooling;
namespace {
+// \brief Counts the number of times MaybeDiagnoseMissingCompleteType
+// is called. Returns the result it was provided on creation.
+class CompleteTypeDiagnoser : public clang::ExternalSemaSource {
+public:
+ CompleteTypeDiagnoser(bool MockResult) : CallCount(0), Result(MockResult) {}
+
+ virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation L, QualType T) {
+ ++CallCount;
+ return Result;
+ }
+
+ int CallCount;
+ bool Result;
+};
+
// \brief Counts the number of err_using_directive_member_suggest diagnostics
// correcting from one namespace to another while still passing all diagnostics
// along a chain of consumers.
@@ -211,4 +226,41 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
ASSERT_EQ(1, Watcher.SeenCount);
}
+// We should only try MaybeDiagnoseMissingCompleteType if we can't otherwise
+// solve the problem.
+TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) {
+ llvm::OwningPtr<ExternalSemaSourceInstaller> Installer(
+ new ExternalSemaSourceInstaller);
+ CompleteTypeDiagnoser Diagnoser(false);
+ Installer->PushSource(&Diagnoser);
+ std::vector<std::string> Args(1, "-std=c++11");
+ // This code hits the class template specialization/class member of a class
+ // template specialization checks in Sema::RequireCompleteTypeImpl.
+ ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
+ Installer.take(),
+ "template <typename T> struct S { class C { }; }; S<char>::C SCInst;",
+ Args));
+ ASSERT_EQ(0, Diagnoser.CallCount);
+}
+
+// The first ExternalSemaSource where MaybeDiagnoseMissingCompleteType returns
+// true should be the last one called.
+TEST(ExternalSemaSource, FirstDiagnoserTaken) {
+ llvm::OwningPtr<ExternalSemaSourceInstaller> Installer(
+ new ExternalSemaSourceInstaller);
+ CompleteTypeDiagnoser First(false);
+ CompleteTypeDiagnoser Second(true);
+ CompleteTypeDiagnoser Third(true);
+ Installer->PushSource(&First);
+ Installer->PushSource(&Second);
+ Installer->PushSource(&Third);
+ std::vector<std::string> Args(1, "-std=c++11");
+ ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs(
+ Installer.take(), "class Incomplete; Incomplete IncompleteInstance;",
+ Args));
+ ASSERT_EQ(1, First.CallCount);
+ ASSERT_EQ(1, Second.CallCount);
+ ASSERT_EQ(0, Third.CallCount);
+}
+
} // anonymous namespace
OpenPOWER on IntegriCloud