Decl printer: fix CXXConstructExpr with implicit default argument

Patch by Will Wilson.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173630 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index b400522..6057f60 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -646,9 +646,13 @@
   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 << "(";
diff --git a/test/SemaCXX/ast-print.cpp b/test/SemaCXX/ast-print.cpp
index d41c347..9ce1f8d 100644
--- a/test/SemaCXX/ast-print.cpp
+++ b/test/SemaCXX/ast-print.cpp
@@ -99,3 +99,24 @@
   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;
+}
+