[clang] 7aac15d - Revert "[clang] Dont print implicit forrange initializer"

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 05:59:26 PDT 2022


Author: Nico Weber
Date: 2022-06-17T08:59:17-04:00
New Revision: 7aac15d5df6cfa03b802e055b63227a95fa1734e

URL: https://github.com/llvm/llvm-project/commit/7aac15d5df6cfa03b802e055b63227a95fa1734e
DIFF: https://github.com/llvm/llvm-project/commit/7aac15d5df6cfa03b802e055b63227a95fa1734e.diff

LOG: Revert "[clang] Dont print implicit forrange initializer"

This reverts commit 32805e60c9de1f82887cd2af30d247dcabd2e1d3.
Broke check-clang, see comments on https://reviews.llvm.org/D127863

Added: 
    

Modified: 
    clang/lib/AST/DeclPrinter.cpp
    clang/unittests/AST/DeclPrinterTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index c6a392c9c01b5..faafe307f03cf 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -895,15 +895,12 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
   Expr *Init = D->getInit();
   if (!Policy.SuppressInitializers && Init) {
     bool ImplicitInit = false;
-    if (D->isCXXForRangeDecl()) {
-      // FIXME: We should print the range expression instead.
-      ImplicitInit = true;
-    } else if (CXXConstructExpr *Construct =
-                   dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
+    if (CXXConstructExpr *Construct =
+            dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
       if (D->getInitStyle() == VarDecl::CallInit &&
           !Construct->isListInitialization()) {
         ImplicitInit = Construct->getNumArgs() == 0 ||
-                       Construct->getArg(0)->isDefaultArgument();
+          Construct->getArg(0)->isDefaultArgument();
       }
     }
     if (!ImplicitInit) {

diff  --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp
index 11dca6ed68167..c2d7d78738f96 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1426,7 +1426,4 @@ TEST(DeclPrinter, VarDeclWithInitializer) {
   ASSERT_TRUE(PrintedDeclCXX17Matches(
       "int a = 0x15;", namedDecl(hasName("a")).bind("id"), "int a = 0x15",
       [](PrintingPolicy &Policy) { Policy.ConstantsAsWritten = true; }));
-  ASSERT_TRUE(
-      PrintedDeclCXX17Matches("void foo() {int arr[42]; for(int a : arr);}",
-                              namedDecl(hasName("a")).bind("id"), "int a"));
 }


        


More information about the cfe-commits mailing list