]> granicus.if.org Git - clang/commitdiff
Move a test from static-assert.cpp to DeclPrinterTest
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 5 Jun 2015 22:40:53 +0000 (22:40 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 5 Jun 2015 22:40:53 +0000 (22:40 +0000)
It's better not to rely on the diagnostics engine to pretty print the
argument to decltype.  Instead, exercise the functionality in
DeclPrinterTest.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239197 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
test/SemaCXX/static-assert.cpp
unittests/AST/DeclPrinterTest.cpp

index 7f9764619c2b2f92911d14b924082bef25bfe42d..94c77f7f73ba8b85f36a5fae9b0450b92df102f0 100644 (file)
@@ -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
index 04d3a32563139338037a06207b6dba93565cc54a..59c204d370a642b93c09d8ead78e72e491209ec7 100644 (file)
@@ -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);
index 52be1a3904254175696a95223643f7cda3389038..7de4d07b50b8e3f0c8819c03adc5d8615511c825 100644 (file)
@@ -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;
-      })){};
-}
index 070b4daabb8f5e51b704fef49566e71efe647871..d8cb97709229be85185846194b47d1794b2c77e1 100644 (file)
@@ -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"