blob: fcaa2c839d6cbc776eb247fe270a709f45e3febe [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Charles Lie7cbb3e2015-11-17 20:25:05 +00002// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
Chris Lattneraa9c7ae2008-04-08 04:40:51 +00005void f(int i);
Chris Lattner0369c572008-11-23 23:12:31 +00006void f(int i = 0); // expected-note {{previous definition is here}}
Chris Lattneraa9c7ae2008-04-08 04:40:51 +00007void 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;
Douglas Gregor4f4946a2010-04-22 00:20:18 +000020void i(int = s) { } // expected-error {{no viable conversion}} \
21// expected-note{{passing argument to parameter here}}
Douglas Gregor5496d4c2008-11-04 13:57:51 +000022
23struct X {
24 X(int);
25};
26
Kaelyn Uhrain476c8232013-07-08 23:13:44 +000027void j(X x = 17); // expected-note{{'::j' declared here}}
Douglas Gregor5496d4c2008-11-04 13:57:51 +000028
Charles Lie7cbb3e2015-11-17 20:25:05 +000029struct 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
Douglas Gregor5496d4c2008-11-04 13:57:51 +000034 explicit Y(int);
35};
36
Douglas Gregor4f4946a2010-04-22 00:20:18 +000037void k(Y y = 17); // expected-error{{no viable conversion}} \
38// expected-note{{passing argument to parameter 'y' here}}
Douglas Gregor58354032008-12-24 00:01:03 +000039
Douglas Gregor4f4946a2010-04-22 00:20:18 +000040void kk(Y = 17); // expected-error{{no viable conversion}} \
41// expected-note{{passing argument to parameter here}}
James Molloye9430032012-03-13 08:55:35 +000042
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 {
Kaelyn Uhrain476c8232013-07-08 23:13:44 +000056 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}}
Richard Smithd72da152012-05-15 06:21:54 +000063 }
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}}
James Molloye9430032012-03-13 08:55:35 +000070 }
71}
Serge Pavlovb4b35782014-07-22 01:54:49 +000072
73int pr20055_f(int x = 0, int y = UNDEFINED); // expected-error{{use of undeclared identifier}}
74int pr20055_v = pr20055_f(0);
Richard Smith5971e8c2014-08-27 22:31:34 +000075
76void PR20769() { void PR20769(int = 1); }
77void PR20769(int = 2);
78
79void PR20769_b(int = 1);
80void PR20769_b() { void PR20769_b(int = 2); }