Clang Project

clang_source_code/test/SemaCXX/complex-overload.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2char *foo(float);
3
4void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) {
5  char *cp1 = foo(fv);
6  char *cp2 = foo(dv);
7  // Note: GCC and EDG reject these two, they are valid C99 conversions but
8  // shouldn't be accepted in C++ because the result is surprising.
9  char *cp3 = foo(fc); // expected-error {{implicit conversion from '_Complex float' to 'float' is not permitted in C++}}
10  char *cp4 = foo(dc); // expected-error {{implicit conversion from '_Complex double' to 'float' is not permitted in C++}}
11}
12
13int *foo(float _Complex);
14
15void test_foo_2(float fv, double dv, float _Complex fc, double _Complex dc) {
16  char *cp1 = foo(fv);
17  char *cp2 = foo(dv);
18  int *ip = foo(fc);
19  int *lp = foo(dc);
20}
21
22long *foo(double _Complex);
23
24void test_foo_3(float fv, double dv, float _Complex fc, double _Complex dc) {
25  char *cp1 = foo(fv);
26  char *cp2 = foo(dv);
27  int *ip = foo(fc);
28  long *lp = foo(dc);
29}
30
31char *promote_or_convert(double _Complex);  // expected-note{{candidate function}}
32int *promote_or_convert(long double _Complex); // expected-note{{candidate function}} 
33
34void test_promote_or_convert(float f, float _Complex fc) {
35  char *cp = promote_or_convert(fc);
36  int *ip2 = promote_or_convert(f); // expected-error{{call to 'promote_or_convert' is ambiguous}}
37}
38
39char *promote_or_convert2(float);
40int *promote_or_convert2(double _Complex);
41
42void test_promote_or_convert2(float _Complex fc) {
43  int *cp = promote_or_convert2(fc);
44}
45
46char *promote_or_convert3(int _Complex); // expected-note {{candidate}}
47int *promote_or_convert3(long _Complex); // expected-note {{candidate}}
48
49void test_promote_or_convert3(short _Complex sc) {
50  char *cp1 = promote_or_convert3(sc);
51  char *cp2 = promote_or_convert3(1i);
52  int *cp3 = promote_or_convert3(1il);
53  int *cp4 = promote_or_convert3(1ill); // expected-error {{ambiguous}}
54}
55
56char &convert4(short _Complex);
57char &test_convert4 = convert4(1i);
58