summaryrefslogtreecommitdiff
path: root/test/SemaCXX
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-11-15 17:11:53 +0000
committerHans Wennborg <hans@hanshq.net>2017-11-15 17:11:53 +0000
commita53ee5453ba652fc640467847415dd44c24fed02 (patch)
tree5772e739dccac61b89fec8f957d3d851464734a4 /test/SemaCXX
parent0b7fe98286274f0bfbc4f8335208c5e01217d019 (diff)
BuiltinOperatorOverloadBuilder: Don't consider types that are unavailable on the target (PR35174)
In the PR, Clang ended up in a situation where it tried to mangle the __float128 type, which isn't supported when targetingt MSVC, because Clang instantiated a variable template with that type when searching for a conversion to use in an arithmetic expression. Differential revision: https://reviews.llvm.org/D39579 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX')
-rw-r--r--test/SemaCXX/microsoft-vs-float128.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/SemaCXX/microsoft-vs-float128.cpp b/test/SemaCXX/microsoft-vs-float128.cpp
new file mode 100644
index 0000000000..d271e47003
--- /dev/null
+++ b/test/SemaCXX/microsoft-vs-float128.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 -DMS %s
+
+template <bool> struct enable_if {};
+template<> struct enable_if<true> { typedef void type; };
+
+template <typename, typename> struct is_same { static constexpr bool value = false; };
+template <typename T> struct is_same<T, T> { static constexpr bool value = true; };
+
+
+
+
+struct S {
+ // The only numeric types S can be converted to is __int128 and __float128.
+ template <typename T, typename = typename enable_if<
+ !((__is_integral(T) && sizeof(T) != 16) ||
+ is_same<T, float>::value ||
+ is_same<T, double>::value ||
+ is_same<T, long double>::value)>::type>
+ operator T() { return T(); }
+};
+
+void f() {
+#ifdef MS
+ // When targeting Win32, __float128 and __int128 do not exist, so the S
+ // object cannot be converted to anything usable in the expression.
+ // expected-error@+2{{invalid operands to binary expression ('S' and 'double')}}
+#endif
+ double d = S() + 1.0;
+#ifndef MS
+ // expected-error@-2{{use of overloaded operator '+' is ambiguous}}
+ // expected-note@-3 36{{built-in candidate operator+}}
+#endif
+}