File: microsoft-vs-float128.cpp

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (36 lines) | stat: -rw-r--r-- 1,552 bytes parent folder | download | duplicates (23)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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 are [unsigned] __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 {{built-in candidate operator+(__float128, double)}}
  // expected-note@-4 {{built-in candidate operator+(__int128, double)}}
  // expected-note@-5 {{built-in candidate operator+(unsigned __int128, double)}}
#endif
}