xref: /aosp_15_r20/external/clang/test/SemaCXX/dcl_ambig_res.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // PR13819
4*67e74705SXin Li // REQUIRES: LP64
5*67e74705SXin Li 
6*67e74705SXin Li // [dcl.ambig.res]p1:
7*67e74705SXin Li struct S {
8*67e74705SXin Li   S(int);
9*67e74705SXin Li   void bar();
10*67e74705SXin Li };
11*67e74705SXin Li 
12*67e74705SXin Li int returns_an_int();
13*67e74705SXin Li 
foo(double a)14*67e74705SXin Li void foo(double a)
15*67e74705SXin Li {
16*67e74705SXin Li   S w(int(a)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
17*67e74705SXin Li   w(17);
18*67e74705SXin Li   S x1(int()); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
19*67e74705SXin Li   x1(&returns_an_int);
20*67e74705SXin Li   S y((int)a);
21*67e74705SXin Li   y.bar();
22*67e74705SXin Li   S z = int(a);
23*67e74705SXin Li   z.bar();
24*67e74705SXin Li }
25*67e74705SXin Li 
26*67e74705SXin Li // [dcl.ambig.res]p3:
27*67e74705SXin Li char *p;
28*67e74705SXin Li void *operator new(__SIZE_TYPE__, int);
foo3()29*67e74705SXin Li void foo3() {
30*67e74705SXin Li   const int x = 63;
31*67e74705SXin Li   new (int(*p)) int; //new-placement expression
32*67e74705SXin Li   new (int(*[x])); //new type-id
33*67e74705SXin Li }
34*67e74705SXin Li 
35*67e74705SXin Li // [dcl.ambig.res]p4:
36*67e74705SXin Li template <class T>  // expected-note{{here}}
37*67e74705SXin Li struct S4 {
38*67e74705SXin Li   T *p;
39*67e74705SXin Li };
40*67e74705SXin Li S4<int()> x; //type-id
41*67e74705SXin Li S4<int(1)> y; // expected-error{{must be a type}}
42*67e74705SXin Li 
43*67e74705SXin Li // [dcl.ambig.res]p5:
foo5()44*67e74705SXin Li void foo5()
45*67e74705SXin Li {
46*67e74705SXin Li   (void)sizeof(int(1)); //expression
47*67e74705SXin Li   (void)sizeof(int()); // expected-error{{function type}}
48*67e74705SXin Li }
49*67e74705SXin Li 
50*67e74705SXin Li // [dcl.ambig.res]p6:
foo6()51*67e74705SXin Li void foo6()
52*67e74705SXin Li {
53*67e74705SXin Li   (void)(int(1)); //expression
54*67e74705SXin Li   (void)(int())1; // expected-error{{to 'int ()'}}
55*67e74705SXin Li }
56*67e74705SXin Li 
57*67e74705SXin Li // [dcl.ambig.res]p7:
58*67e74705SXin Li class C7 { };
f7(int (C7))59*67e74705SXin Li void f7(int(C7)) { } // expected-note{{candidate}}
60*67e74705SXin Li int g7(C7);
foo7()61*67e74705SXin Li void foo7() {
62*67e74705SXin Li   f7(1); // expected-error{{no matching function}}
63*67e74705SXin Li   f7(g7); //OK
64*67e74705SXin Li }
65*67e74705SXin Li 
h7(int * (C7[10]))66*67e74705SXin Li void h7(int *(C7[10])) { } // expected-note{{previous}}
h7(int * (* _fp)(C7 _parm[10]))67*67e74705SXin Li void h7(int *(*_fp)(C7 _parm[10])) { } // expected-error{{redefinition}}
68*67e74705SXin Li 
69*67e74705SXin Li struct S5 {
70*67e74705SXin Li   static bool const value = false;
71*67e74705SXin Li };
foo8()72*67e74705SXin Li int foo8() {
73*67e74705SXin Li   int v(int(S5::value)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}} expected-error{{parameter declarator cannot be qualified}}
74*67e74705SXin Li }
75*67e74705SXin Li 
76*67e74705SXin Li template<typename T>
77*67e74705SXin Li void rdar8739801( void (T::*)( void ) __attribute__((unused)) );
78