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