[cfe-commits] r173630 - Decl printer: fix CXXConstructExpr with implicit default argument
Dmitri Gribenko
gribozavr at gmail.com
Sun Jan 27 13:28:24 PST 2013
Author: gribozavr
Date: Sun Jan 27 15:28:24 2013
New Revision: 173630
URL: http://llvm.org/viewvc/llvm-project?rev=173630&view=rev
Log:
Decl printer: fix CXXConstructExpr with implicit default argument
Patch by Will Wilson.
Modified:
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/test/SemaCXX/ast-print.cpp
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=173630&r1=173629&r2=173630&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sun Jan 27 15:28:24 2013
@@ -646,9 +646,13 @@ void DeclPrinter::VisitVarDecl(VarDecl *
Expr *Init = D->getInit();
if (!Policy.SuppressInitializers && Init) {
bool ImplicitInit = false;
- if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init))
- ImplicitInit = D->getInitStyle() == VarDecl::CallInit &&
- Construct->getNumArgs() == 0 && !Construct->isListInitialization();
+ if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init)) {
+ if (D->getInitStyle() == VarDecl::CallInit &&
+ !Construct->isListInitialization()) {
+ ImplicitInit = Construct->getNumArgs() == 0 ||
+ Construct->getArg(0)->isDefaultArgument();
+ }
+ }
if (!ImplicitInit) {
if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Out << "(";
Modified: cfe/trunk/test/SemaCXX/ast-print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print.cpp?rev=173630&r1=173629&r2=173630&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ast-print.cpp (original)
+++ cfe/trunk/test/SemaCXX/ast-print.cpp Sun Jan 27 15:28:24 2013
@@ -99,3 +99,24 @@ int test11() {
return test10::M::X<INT>::value;
}
+
+struct DefaultArgClass
+{
+ DefaultArgClass(int a = 1) {}
+};
+
+struct NoArgClass
+{
+ NoArgClass() {}
+};
+
+// CHECK: test12
+// CHECK-NEXT: DefaultArgClass useDefaultArg;
+// CHECK-NEXT: DefaultArgClass overrideDefaultArg(1);
+// CHECK-NEXT: NoArgClass noArg;
+void test12() {
+ DefaultArgClass useDefaultArg;
+ DefaultArgClass overrideDefaultArg(1);
+ NoArgClass noArg;
+}
+
More information about the cfe-commits
mailing list