Add missing test
authorStephen Kelly <steveire@gmail.com>
Sun, 24 May 2020 21:49:00 +0000 (22:49 +0100)
committerStephen Kelly <steveire@gmail.com>
Sun, 24 May 2020 21:50:50 +0000 (22:50 +0100)
clang/lib/AST/Expr.cpp
clang/unittests/AST/ASTTraverserTest.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

index b9b7ca9..4c175ff 100644 (file)
@@ -2909,7 +2909,8 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
   Expr *LastE = nullptr;
   while (E != LastE) {
     LastE = E;
-    E = IgnoreExprNodes(E, IgnoreImplicitSingleStep, IgnoreImpCastsExtraSingleStep,
+    E = IgnoreExprNodes(E, IgnoreImplicitSingleStep,
+                        IgnoreImpCastsExtraSingleStep,
                         IgnoreParensOnlySingleStep);
 
     auto SR = E->getSourceRange();
index affbbe7..5585238 100644 (file)
@@ -291,6 +291,13 @@ void conversionOperator()
     C1 c1 = (*c2);
 }
 
+template <unsigned alignment>
+void template_test() {
+  static_assert(alignment, "");
+}
+void actual_template_test() {
+  template_test<4>();
+}
 )cpp");
 
   {
@@ -410,6 +417,31 @@ VarDecl 'c1'
   `-DeclRefExpr 'c2'
 )cpp");
   }
+
+  {
+    auto FN = ast_matchers::match(
+        functionDecl(hasName("template_test"),
+                     hasDescendant(staticAssertDecl().bind("staticAssert"))),
+        AST->getASTContext());
+    EXPECT_EQ(FN.size(), 2u);
+
+    EXPECT_EQ(dumpASTString(TK_AsIs, FN[1].getNodeAs<Decl>("staticAssert")),
+              R"cpp(
+StaticAssertDecl
+|-ImplicitCastExpr
+| `-SubstNonTypeTemplateParmExpr
+|   `-IntegerLiteral
+`-StringLiteral
+)cpp");
+
+    EXPECT_EQ(dumpASTString(TK_IgnoreUnlessSpelledInSource,
+                            FN[1].getNodeAs<Decl>("staticAssert")),
+              R"cpp(
+StaticAssertDecl
+|-IntegerLiteral
+`-StringLiteral
+)cpp");
+  }
 }
 
 TEST(Traverse, IgnoreUnlessSpelledInSourceStructs) {
index e8b0a31..6bd8fcf 100644 (file)
@@ -1867,6 +1867,26 @@ void conversionOperator()
                             hasDescendant(varDecl(
                                 hasName("c1"), hasInitializer(unaryOperator(
                                                    hasOperatorName("*")))))))));
+
+  Code = R"cpp(
+
+template <unsigned alignment>
+void template_test() {
+  static_assert(alignment, "");
+}
+void actual_template_test() {
+  template_test<4>();
+}
+
+)cpp";
+  EXPECT_TRUE(matches(
+      Code,
+      traverse(TK_AsIs,
+               staticAssertDecl(has(implicitCastExpr(has(
+                   substNonTypeTemplateParmExpr(has(integerLiteral())))))))));
+
+  EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
+                                     staticAssertDecl(has(integerLiteral())))));
 }
 
 template <typename MatcherT>