File: p7.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (56 lines) | stat: -rw-r--r-- 1,994 bytes parent folder | download | duplicates (19)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: %clang_cc1 -std=c++11 -verify %s
// RUN: %clang_cc1 -std=c++2a -verify %s

struct Q { typedef int type; };

// "The substitution occurs in all types and expressions that are used in [...]
// template parameter declarations." In particular, we must substitute into the
// type of a parameter pack that is not a pack expansion, even if we know the
// corresponding argument pack is empty.
template<typename T, typename T::type...> void a(T);
int &a(...);
int &a_disabled = a(0);
int &a_enabled = a(Q()); // expected-error {{cannot bind to a temporary of type 'void'}}

template<typename T, template<typename T::type> class ...X> void b(T);
int &b(...);
int &b_disabled = b(0);
int &b_enabled = b(Q()); // expected-error {{cannot bind to a temporary of type 'void'}}

template<typename T, template<typename T::type...> class ...X> void c(T);
int &c(...);
int &c_disabled = c(0);
int &c_enabled = c(Q()); // expected-error {{cannot bind to a temporary of type 'void'}}

// The substitution proceeds in lexical order and stops when a condition that
// causes deduction to fail is encountered.
#if __cplusplus > 201702L
namespace reversed_operator_substitution_order {
  struct X { X(int); };
  struct Y { Y(int); };
  struct Cat {};
  namespace no_adl {
    Cat operator<=>(Y, X);
    bool operator<(int, Cat);

    template<typename T> struct indirect_sizeof {
      static_assert(sizeof(T) != 0);
      static const auto value = sizeof(T);
    };

    // We should substitute into the construction of the X object before the
    // construction of the Y object, so this is a SFINAE case rather than a
    // hard error. This requires substitution to proceed in lexical order
    // despite the prior rewrite to
    //    0 < (Y(...) <=> X(...))
    template<typename T> float &f(
        decltype(
          X(sizeof(T)) < Y(indirect_sizeof<T>::value)
        )
    );
    template<typename T> int &f(...);
  }
  int &r = no_adl::f<void>(true);
  float &s = no_adl::f<int>(true);
}
#endif