| Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| Chandler Carruth | 8fa1e7e | 2010-02-25 07:20:54 +0000 | [diff] [blame] | 2 | char *foo(float); |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 3 | |
| 4 | void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) { |
| 5 | char *cp1 = foo(fv); |
| 6 | char *cp2 = foo(dv); |
| Tim Northover | 0241637 | 2017-08-08 23:18:05 +0000 | [diff] [blame] | 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++}} |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 11 | } |
| 12 | |
| Chandler Carruth | 8fa1e7e | 2010-02-25 07:20:54 +0000 | [diff] [blame] | 13 | int *foo(float _Complex); |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 14 | |
| 15 | void test_foo_2(float fv, double dv, float _Complex fc, double _Complex dc) { |
| 16 | char *cp1 = foo(fv); |
| Chandler Carruth | 8fa1e7e | 2010-02-25 07:20:54 +0000 | [diff] [blame] | 17 | char *cp2 = foo(dv); |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 18 | int *ip = foo(fc); |
| Chandler Carruth | 8fa1e7e | 2010-02-25 07:20:54 +0000 | [diff] [blame] | 19 | int *lp = foo(dc); |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| Chandler Carruth | 8fa1e7e | 2010-02-25 07:20:54 +0000 | [diff] [blame] | 22 | long *foo(double _Complex); |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 23 | |
| 24 | void test_foo_3(float fv, double dv, float _Complex fc, double _Complex dc) { |
| 25 | char *cp1 = foo(fv); |
| Chandler Carruth | 8fa1e7e | 2010-02-25 07:20:54 +0000 | [diff] [blame] | 26 | char *cp2 = foo(dv); |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 27 | int *ip = foo(fc); |
| 28 | long *lp = foo(dc); |
| 29 | } |
| 30 | |
| 31 | char *promote_or_convert(double _Complex); // expected-note{{candidate function}} |
| 32 | int *promote_or_convert(long double _Complex); // expected-note{{candidate function}} |
| 33 | |
| 34 | void test_promote_or_convert(float f, float _Complex fc) { |
| 35 | char *cp = promote_or_convert(fc); |
| Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 36 | int *ip2 = promote_or_convert(f); // expected-error{{call to 'promote_or_convert' is ambiguous}} |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | char *promote_or_convert2(float); |
| 40 | int *promote_or_convert2(double _Complex); |
| 41 | |
| Douglas Gregor | 6752502 | 2009-02-12 00:26:06 +0000 | [diff] [blame] | 42 | void test_promote_or_convert2(float _Complex fc) { |
| Douglas Gregor | 78ca74d | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 43 | int *cp = promote_or_convert2(fc); |
| 44 | } |
| Douglas Gregor | 6752502 | 2009-02-12 00:26:06 +0000 | [diff] [blame] | 45 | |
| Richard Smith | b8a9824 | 2013-05-10 20:29:50 +0000 | [diff] [blame] | 46 | char *promote_or_convert3(int _Complex); // expected-note {{candidate}} |
| 47 | int *promote_or_convert3(long _Complex); // expected-note {{candidate}} |
| Douglas Gregor | 6752502 | 2009-02-12 00:26:06 +0000 | [diff] [blame] | 48 | |
| 49 | void test_promote_or_convert3(short _Complex sc) { |
| Richard Smith | b8a9824 | 2013-05-10 20:29:50 +0000 | [diff] [blame] | 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}} |
| Douglas Gregor | 6752502 | 2009-02-12 00:26:06 +0000 | [diff] [blame] | 54 | } |
| Richard Smith | b8a9824 | 2013-05-10 20:29:50 +0000 | [diff] [blame] | 55 | |
| 56 | char &convert4(short _Complex); |
| 57 | char &test_convert4 = convert4(1i); |