File: cwg29xx.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (173 lines) | stat: -rw-r--r-- 4,572 bytes parent folder | download | duplicates (3)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s
// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected,since-cxx11 %s
// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected,since-cxx11 %s
// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected,since-cxx11 %s
// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx11,since-cxx20 %s
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23 %s
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23,since-cxx26 %s

// cxx98-no-diagnostics

namespace cwg2913 { // cwg2913: 20

#if __cplusplus >= 202002L

template<typename T>
struct R {
  R(T);
  R(T, T);
};

template<typename T>
R(T) -> R<T> requires true;

template<typename T>
R(T, T) requires true -> R<T>;
// since-cxx20-error@-1 {{expected function body after function declarator}}

#endif

} // namespace cwg2913

namespace cwg2915 { // cwg2915: 20
#if __cplusplus >= 202302L
struct A {
  void f(this void);
  // since-cxx23-error@-1 {{explicit object parameter cannot have 'void' type}}
};
#endif
} // namespace cwg2915

namespace cwg2917 { // cwg2917: 20 review 2024-07-30
#if __cplusplus >= 201103L
template <typename>
class Foo;

template<class ...>
struct C {
  struct Nested { };
};

struct S {
  template <typename>
  friend class Foo, int;
  // since-cxx11-error@-1 {{a friend declaration that befriends a template must contain exactly one type-specifier}}

  template <typename ...Ts>
  friend class C<Ts>::Nested...;
  // since-cxx11-error@-1 {{friend declaration expands pack 'Ts' that is declared it its own template parameter list}}
};
#endif
} // namespace cwg2917

namespace cwg2918 { // cwg2918: 21

#if __cplusplus >= 202002L

namespace Example1 {

template<bool B> struct X {
  void f(short) requires B;
  void f(long);
  template<typename> void g(short) requires B;
  template<typename> void g(long);
};

void test() {
  &X<true>::f;      // since-cxx20-error {{reference to overloaded function could not be resolved}}
  &X<true>::g<int>; // since-cxx20-error {{reference to overloaded function could not be resolved}}
}

} // namespace Example1

namespace Example2 {

template <bool B> struct X {
  static constexpr int f(short) requires B {
    return 42;
  }
  static constexpr int f(short) {
    return 24;
  }
};

template <typename T>
constexpr int f(T) { return 1; }

template <typename T>
  requires __is_same(T, int)
constexpr int f(T) { return 2; }

void test() {
  constexpr auto x = &X<true>::f;
  static_assert(__is_same(decltype(x), int(*const)(short)), "");
  static_assert(x(0) == 42, "");

  constexpr auto y = &X<false>::f;
  static_assert(__is_same(decltype(y), int(*const)(short)));
  static_assert(y(0) == 24, "");
  
  constexpr auto z = &f<int>;
  static_assert(__is_same(decltype(z), int(*const)(int)));
  static_assert(z(0) == 2, "");

  // C++ [temp.deduct.call]p6:
  //   If the argument is an overload set containing one or more function templates,
  //   the parameter is treated as a non-deduced context.
  auto w = f; // since-cxx20-error {{variable 'w' with type 'auto' has incompatible initializer of type '<overloaded function type>'}}
}

} // namespace Example2
#endif

#if __cplusplus >= 201103L
namespace Example3 {

template <typename T> void f(T &&, void (*)(T &&)); // #cwg2918_f

void g(int &);
inline namespace A {
void g(short &&);
}
inline namespace B {
void g(short &&);
}

void q() {
  int x;
  f(x, g);
  // since-cxx11-error@-1 {{no matching function for call to 'f'}}
  //   since-cxx11-note@#cwg2918_f {{candidate template ignored: deduced conflicting types for parameter 'T' ('int &' vs. 'short')}}
}

} // namespace Example3

#endif

} // namespace cwg2918

#if __cplusplus > 202302L
namespace std {
  using size_t = decltype(sizeof(0));
} // namespace std
void *operator new(std::size_t, void *p) { return p; }
void* operator new[] (std::size_t, void* p) {return p; }
#endif

namespace cwg2922 { // cwg2922: 20
#if __cplusplus > 202302L
union U { int a, b; };
constexpr U nondeterministic(bool i) {
  if(i) {
    U u;
    new (&u) int(); // #cwg2922-placement-new
    return u;
  }
  return {};
}
constexpr U _ = nondeterministic(true);
// since-cxx26-error@-1 {{constexpr variable '_' must be initialized by a constant expression}}
//   since-cxx26-note@#cwg2922-placement-new {{placement new would change type of storage from 'U' to 'int'}}
//   since-cxx26-note@-3 {{in call to 'nondeterministic(true)'}}
#endif
} // namespace cwg2922