[PATCH] D127863: [clang] Dont print implicit forrange initializer
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 17 02:30:22 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32805e60c9de: [clang] Dont print implicit forrange initializer (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127863/new/
https://reviews.llvm.org/D127863
Files:
clang/lib/AST/DeclPrinter.cpp
clang/unittests/AST/DeclPrinterTest.cpp
Index: clang/unittests/AST/DeclPrinterTest.cpp
===================================================================
--- clang/unittests/AST/DeclPrinterTest.cpp
+++ clang/unittests/AST/DeclPrinterTest.cpp
@@ -1426,4 +1426,7 @@
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"));
}
Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -895,12 +895,15 @@
Expr *Init = D->getInit();
if (!Policy.SuppressInitializers && Init) {
bool ImplicitInit = false;
- if (CXXConstructExpr *Construct =
- dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
+ if (D->isCXXForRangeDecl()) {
+ // FIXME: We should print the range expression instead.
+ ImplicitInit = true;
+ } else 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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127863.437825.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220617/1f6b825e/attachment.bin>
More information about the cfe-commits
mailing list