107 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4 5void f(int i);6void f(int i = 0); // expected-note {{previous definition is here}}7void f(int i = 17); // expected-error {{redefinition of default argument}}8 9 10void g(int i, int j, int k = 3);11void g(int i, int j = 2, int k);12void g(int i = 1, int j, int k);13 14void 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 19struct S { } s;20void i(int = s) { } // expected-error {{no viable conversion}} \21// expected-note{{passing argument to parameter here}}22 23struct X { 24 X(int);25};26 27void j(X x = 17); // expected-note{{'::j' declared here}}28 29struct Y { // expected-note 2{{candidate constructor (the implicit copy constructor) not viable}}30#if __cplusplus >= 201103L // C++11 or later31// expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}}32#endif33 34 explicit Y(int); // expected-note 2{{explicit constructor is not a candidate}}35};36 37void k(Y y = 17); // expected-error{{no viable conversion}} \38// expected-note{{passing argument to parameter 'y' here}}39 40void kk(Y = 17); // expected-error{{no viable conversion}} \41// expected-note{{passing argument to parameter here}}42 43int 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 53int 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 66int 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 73int pr20055_f(int x = 0, int y = UNDEFINED); // expected-error{{use of undeclared identifier}}74int pr20055_v = pr20055_f(0);75 76void PR20769() { void PR20769(int = 1); }77void PR20769(int = 2);78 79void PR20769_b(int = 1);80void PR20769_b() { void PR20769_b(int = 2); }81 82#if __cplusplus >= 201103L83template<typename T> constexpr int f1() { return 0; }84// This is OK, but in order to see that we must instantiate f<int>, despite it85// being in an unused default argument.86void g1(char c = {f1<int>()}) {} // expected-warning {{braces around scalar}}87 88// This is formally ill-formed, but we choose to not trigger instantiation here89// (at least, not until g2 is actually called in a way that uses the default90// argument).91template<typename T> int f2() { return T::error; }92void g2(int c = f2<int>()) {}93 94// FIXME: Provide a note pointing at the first use of the default argument?95template<typename T> int f3() { return T::error; } // expected-error {{no members}}96void g3(int c = f3<int>()) {} // expected-note {{in instantiation of}}97void use_g3() { g3(); }98 99namespace PR47682 {100 inline namespace A {101 void f(int = 0);102 }103}104void PR47682::f(int) {}105void PR47682_test() { PR47682::f(); }106#endif107