From 2b6d863890e81a6bf351ed0ef67b1c237796bba0 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 5 Jun 2015 22:40:53 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239197 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 17 +++++++++++++++++ lib/ASTMatchers/Dynamic/Registry.cpp | 1 + test/SemaCXX/static-assert.cpp | 9 --------- unittests/AST/DeclPrinterTest.cpp | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 7f9764619c..94c77f7f73 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/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/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp index 04d3a32563..59c204d370 100644 --- a/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/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/test/SemaCXX/static-assert.cpp b/test/SemaCXX/static-assert.cpp index 52be1a3904..7de4d07b50 100644 --- a/test/SemaCXX/static-assert.cpp +++ b/test/SemaCXX/static-assert.cpp @@ -51,12 +51,3 @@ StaticAssertProtected 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/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index 070b4daabb..d8cb977092 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -157,6 +157,17 @@ public: "input.cc"); } +::testing::AssertionResult +PrintedDeclCXX1ZMatches(StringRef Code, const DeclarationMatcher &NodeMatch, + StringRef ExpectedPrinted) { + std::vector 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" -- 2.40.0