blob: 77d2498812908a95139a3b454b1e58fa66fff61b [file] [log] [blame]
Hans Wennborg82371412017-11-15 17:11:53 +00001// RUN: %clang_cc1 -triple x86_64-linux-gnu -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
2// RUN: %clang_cc1 -triple i686-pc-win32 -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 -DMS %s
3
4template <bool> struct enable_if {};
5template<> struct enable_if<true> { typedef void type; };
6
7template <typename, typename> struct is_same { static constexpr bool value = false; };
8template <typename T> struct is_same<T, T> { static constexpr bool value = true; };
9
10
11
12
13struct S {
Richard Smith70f59b52019-10-23 17:54:10 -070014 // The only numeric types S can be converted to are [unsigned] __int128 and __float128.
Hans Wennborg82371412017-11-15 17:11:53 +000015 template <typename T, typename = typename enable_if<
16 !((__is_integral(T) && sizeof(T) != 16) ||
17 is_same<T, float>::value ||
18 is_same<T, double>::value ||
19 is_same<T, long double>::value)>::type>
20 operator T() { return T(); }
21};
22
23void f() {
24#ifdef MS
25 // When targeting Win32, __float128 and __int128 do not exist, so the S
26 // object cannot be converted to anything usable in the expression.
27 // expected-error@+2{{invalid operands to binary expression ('S' and 'double')}}
28#endif
29 double d = S() + 1.0;
30#ifndef MS
31 // expected-error@-2{{use of overloaded operator '+' is ambiguous}}
Richard Smith70f59b52019-10-23 17:54:10 -070032 // expected-note@-3 {{built-in candidate operator+(__float128, double)}}
33 // expected-note@-4 {{built-in candidate operator+(__int128, double)}}
34 // expected-note@-5 {{built-in candidate operator+(unsigned __int128, double)}}
Hans Wennborg82371412017-11-15 17:11:53 +000035#endif
36}