From 145449b1e420787bb99721a429341fa6be3adfb6 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 3 Jul 2022 16:10:23 +0200 Subject: Vendor import of llvm-project main llvmorg-15-init-15358-g53dc0f107877. --- clang/lib/AST/DeclPrinter.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'clang/lib/AST/DeclPrinter.cpp') diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index c3f1d1544f79..c6a392c9c01b 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -680,6 +680,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (FT->isVariadic()) { if (D->getNumParams()) POut << ", "; POut << "..."; + } else if (!D->getNumParams() && !Context.getLangOpts().CPlusPlus) { + // The function has a prototype, so it needs to retain the prototype + // in C. + POut << "void"; } } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) { for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { @@ -891,12 +895,15 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { Expr *Init = D->getInit(); if (!Policy.SuppressInitializers && Init) { bool ImplicitInit = false; - if (CXXConstructExpr *Construct = - dyn_cast(Init->IgnoreImplicit())) { + if (D->isCXXForRangeDecl()) { + // FIXME: We should print the range expression instead. + ImplicitInit = true; + } else if (CXXConstructExpr *Construct = + dyn_cast(Init->IgnoreImplicit())) { if (D->getInitStyle() == VarDecl::CallInit && !Construct->isListInitialization()) { ImplicitInit = Construct->getNumArgs() == 0 || - Construct->getArg(0)->isDefaultArgument(); + Construct->getArg(0)->isDefaultArgument(); } } if (!ImplicitInit) { -- cgit v1.2.3