1// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
5// Tests that dependent expressions are always allowed, whereas non-dependent
6// are checked as usual.
7
8#include <stddef.h>
9
10// Fake typeid, lacking a typeinfo header.
11namespace std { class type_info {}; }
12
13struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
14#if __cplusplus >= 201103L // C++11 or later
15// expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}
16#endif
17
18template<typename T>
19int f0(T x) {
20  return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;
21}
22
23template <typename T, typename U>
24T f1(T t1, U u1, int i1)
25{
26  T t2 = i1;
27  t2 = i1 + u1;
28  ++u1;
29  u1++;
30  int i2 = u1;
31
32  i1 = t1[u1];
33  i1 *= t1;
34
35  i1(u1, t1); // error
36  u1(i1, t1);
37
38  U u2 = (T)i1;
39  static_cast<void>(static_cast<U>(reinterpret_cast<T>(
40    dynamic_cast<U>(const_cast<T>(i1)))));
41
42  new U(i1, t1);
43  new int(t1, u1);
44  new (t1, u1) int;
45  delete t1;
46
47  dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}
48  dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}
49  dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}
50  i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}}
51
52  return u1;
53}
54
55template<typename T>
56void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}
57
58void f3() {
59  f2<int*>(0);
60  f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
61}
62