]> granicus.if.org Git - clang/commitdiff
Make sure that we instantiate default function arguments for an
authorDouglas Gregor <dgregor@apple.com>
Mon, 9 Nov 2009 19:27:57 +0000 (19:27 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 9 Nov 2009 19:27:57 +0000 (19:27 +0000)
overloaded operator().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86581 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaTemplate/default-expr-arguments.cpp

index 00a55b9c365364517b8f5e6bb3c79e84c6097bc6..f57ce140e52020d0403eab16fee4ed604cfd098a 100644 (file)
@@ -5420,7 +5420,14 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
       QualType ProtoArgType = Proto->getArgType(i);
       IsError |= PerformCopyInitialization(Arg, ProtoArgType, "passing");
     } else {
-      Arg = CXXDefaultArgExpr::Create(Context, Method->getParamDecl(i));
+      OwningExprResult DefArg
+        = BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i));
+      if (DefArg.isInvalid()) {
+        IsError = true;
+        break;
+      }
+      
+      Arg = DefArg.takeAs<Expr>();
     }
 
     TheCall->setArg(i + 1, Arg);
index c136eee0f62bbffcf52bfa53a8d73f12839b1169..34ac2d967efc205d26dc6410ffc623122704fd74 100644 (file)
@@ -65,8 +65,8 @@ void test_x0(X0<int> xi) {
   xi.f(17);
 }
 
-struct NotDefaultConstructible { // expected-note{{candidate}}
-  NotDefaultConstructible(int); // expected-note{{candidate}}
+struct NotDefaultConstructible { // expected-note 2{{candidate}}
+  NotDefaultConstructible(int); // expected-note 2{{candidate}}
 };
 
 void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) {
@@ -85,6 +85,18 @@ void test_X1() {
   X1<int> x1;
 }
 
+template<typename T>
+struct X2 {
+  void operator()(T = T()); // expected-error{{no matching}}
+};
+
+void test_x2(X2<int> x2i, X2<NotDefaultConstructible> x2n) {
+  x2i();
+  x2i(17);
+  x2n(NotDefaultConstructible(17));
+  x2n(); // expected-note{{in instantiation of default function argument}}
+}
+
 // PR5283
 namespace PR5283 {
 template<typename T> struct A {
@@ -131,3 +143,4 @@ namespace pr5301 {
     h(0);
   }
 }
+