Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
      3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
      4 
      5 void f(int i);
      6 void f(int i = 0); // expected-note {{previous definition is here}}
      7 void f(int i = 17); // expected-error {{redefinition of default argument}}
      8 
      9 
     10 void g(int i, int j, int k = 3);
     11 void g(int i, int j = 2, int k);
     12 void g(int i = 1, int j, int k);
     13 
     14 void h(int i, int j = 2, int k = 3,
     15        int l, // expected-error {{missing default argument on parameter 'l'}}
     16        int,   // expected-error {{missing default argument on parameter}}
     17        int n);// expected-error {{missing default argument on parameter 'n'}}
     18 
     19 struct S { } s;
     20 void i(int = s) { } // expected-error {{no viable conversion}} \
     21 // expected-note{{passing argument to parameter here}}
     22 
     23 struct X {
     24   X(int);
     25 };
     26 
     27 void j(X x = 17); // expected-note{{'::j' declared here}}
     28 
     29 struct Y { // expected-note 2{{candidate constructor (the implicit copy constructor) not viable}}
     30 #if __cplusplus >= 201103L // C++11 or later
     31 // expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}}
     32 #endif
     33 
     34   explicit Y(int);
     35 };
     36 
     37 void k(Y y = 17); // expected-error{{no viable conversion}} \
     38 // expected-note{{passing argument to parameter 'y' here}}
     39 
     40 void kk(Y = 17); // expected-error{{no viable conversion}} \
     41 // expected-note{{passing argument to parameter here}}
     42 
     43 int l () {
     44   int m(int i, int j, int k = 3);
     45   if (1)
     46   {
     47     int m(int i, int j = 2, int k = 4);
     48     m(8);
     49   }
     50   return 0;
     51 }
     52 
     53 int i () {
     54   void j (int f = 4);
     55   {
     56     void j (int f);
     57     j(); // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::j'?}}
     58   }
     59   void jj (int f = 4);
     60   {
     61     void jj (int f); // expected-note{{'jj' declared here}}
     62     jj(); // expected-error{{too few arguments to function call, single argument 'f' was not specified}}
     63   }
     64 }
     65 
     66 int i2() {
     67   void j(int f = 4); // expected-note{{'j' declared here}}
     68   {
     69     j(2, 3); // expected-error{{too many arguments to function call, expected at most single argument 'f', have 2}}
     70   }
     71 }
     72 
     73 int pr20055_f(int x = 0, int y = UNDEFINED); // expected-error{{use of undeclared identifier}}
     74 int pr20055_v = pr20055_f(0);
     75 
     76 void PR20769() { void PR20769(int = 1); }
     77 void PR20769(int = 2);
     78 
     79 void PR20769_b(int = 1);
     80 void PR20769_b() { void PR20769_b(int = 2); }
     81