[PATCH] D127863: [clang] Dont print implicit forrange initializer
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 15 07:56:47 PDT 2022
kadircet created this revision.
kadircet added a reviewer: usaxena95.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.
Fixes https://github.com/clangd/clangd/issues/1158
Repository:
rG LLVM Github Monorepo
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.437176.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220615/41282daa/attachment-0001.bin>
More information about the cfe-commits
mailing list