r239197 - Move a test from static-assert.cpp to DeclPrinterTest
David Majnemer
david.majnemer at gmail.com
Fri Jun 5 15:40:54 PDT 2015
Author: majnemer
Date: Fri Jun 5 17:40:53 2015
New Revision: 239197
URL: http://llvm.org/viewvc/llvm-project?rev=239197&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/test/SemaCXX/static-assert.cpp
cfe/trunk/unittests/AST/DeclPrinterTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=239197&r1=239196&r2=239197&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Jun 5 17:40:53 2015
@@ -1476,6 +1476,23 @@ const internal::VariadicDynCastAllOfMatc
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
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=239197&r1=239196&r2=239197&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Jun 5 17:40:53 2015
@@ -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);
Modified: cfe/trunk/test/SemaCXX/static-assert.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/static-assert.cpp?rev=239197&r1=239196&r2=239197&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/static-assert.cpp (original)
+++ cfe/trunk/test/SemaCXX/static-assert.cpp Fri Jun 5 17:40:53 2015
@@ -51,12 +51,3 @@ StaticAssertProtected<X> sap2; // expect
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;
- })){};
-}
Modified: cfe/trunk/unittests/AST/DeclPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/DeclPrinterTest.cpp?rev=239197&r1=239196&r2=239197&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/DeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/DeclPrinterTest.cpp Fri Jun 5 17:40:53 2015
@@ -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, TestTemplateArgumentLi
// 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"
More information about the cfe-commits
mailing list