summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-06-05 22:40:53 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-06-05 22:40:53 +0000
commit8423df927eb6b24e8821d557c1a26c4cd0f44fcf (patch)
tree7b1e83b3f7c9176bd55444210b78c8d72ef20cb3
parentb41e76bb0bc6aac90e1755477936b216857b05d6 (diff)
downloadbcm5719-llvm-8423df927eb6b24e8821d557c1a26c4cd0f44fcf.tar.gz
bcm5719-llvm-8423df927eb6b24e8821d557c1a26c4cd0f44fcf.zip
Move a test from static-assert.cpp to DeclPrinterTest
It's better not to rely on the diagnostics engine to pretty print the argument to decltype. Instead, exercise the functionality in DeclPrinterTest. llvm-svn: 239197
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h17
-rw-r--r--clang/lib/ASTMatchers/Dynamic/Registry.cpp1
-rw-r--r--clang/test/SemaCXX/static-assert.cpp9
-rw-r--r--clang/unittests/AST/DeclPrinterTest.cpp18
4 files changed, 36 insertions, 9 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 7f9764619c2..94c77f7f73b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1476,6 +1476,23 @@ const internal::VariadicDynCastAllOfMatcher<
Stmt,
ConditionalOperator> conditionalOperator;
+/// \brief Matches a C++ static_assert declaration.
+///
+/// Example:
+/// staticAssertExpr()
+/// matches
+/// static_assert(sizeof(S) == sizeof(int))
+/// in
+/// \code
+/// struct S {
+/// int x;
+/// };
+/// static_assert(sizeof(S) == sizeof(int));
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+ Decl,
+ StaticAssertDecl> staticAssertDecl;
+
/// \brief Matches a reinterpret_cast expression.
///
/// Either the source expression or the destination type can be matched
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 04d3a325631..59c204d370a 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -311,6 +311,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(specifiesTypeLoc);
REGISTER_MATCHER(statementCountIs);
REGISTER_MATCHER(staticCastExpr);
+ REGISTER_MATCHER(staticAssertDecl);
REGISTER_MATCHER(stmt);
REGISTER_MATCHER(stringLiteral);
REGISTER_MATCHER(substNonTypeTemplateParmExpr);
diff --git a/clang/test/SemaCXX/static-assert.cpp b/clang/test/SemaCXX/static-assert.cpp
index 52be1a39042..7de4d07b50b 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -51,12 +51,3 @@ StaticAssertProtected<X> sap2; // expected-note {{instantiation}}
static_assert(true); // expected-warning {{C++1z extension}}
static_assert(false); // expected-error-re {{failed{{$}}}} expected-warning {{extension}}
-
-void PR23756() {
- struct { // expected-note 2 {{no known conversion from}}
- } _ = decltype( // expected-error {{no viable conversion}}
- ({ // expected-warning {{no effect in an unevaluated context}}
- static_assert(true); // expected-warning {{C++1z extension}}
- 1;
- })){};
-}
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp
index 070b4daabb8..d8cb9770922 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -157,6 +157,17 @@ public:
"input.cc");
}
+::testing::AssertionResult
+PrintedDeclCXX1ZMatches(StringRef Code, const DeclarationMatcher &NodeMatch,
+ StringRef ExpectedPrinted) {
+ std::vector<std::string> Args(1, "-std=c++1z");
+ return PrintedDeclMatches(Code,
+ Args,
+ NodeMatch,
+ ExpectedPrinted,
+ "input.cc");
+}
+
::testing::AssertionResult PrintedDeclObjCMatches(
StringRef Code,
const DeclarationMatcher &NodeMatch,
@@ -1264,6 +1275,13 @@ TEST(DeclPrinter, TestTemplateArgumentList15) {
// Should be: with semicolon
}
+TEST(DeclPrinter, TestStaticAssert1) {
+ ASSERT_TRUE(PrintedDeclCXX1ZMatches(
+ "static_assert(true);",
+ staticAssertDecl().bind("id"),
+ "static_assert(true)"));
+}
+
TEST(DeclPrinter, TestObjCMethod1) {
ASSERT_TRUE(PrintedDeclObjCMatches(
"__attribute__((objc_root_class)) @interface X\n"
OpenPOWER on IntegriCloud