• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
11 namespace std { class type_info {}; }
12 
13 struct 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 
18 template<typename T>
f0(T x)19 int f0(T x) {
20   return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;
21 }
22 
23 template <typename T, typename U>
f1(T t1,U u1,int i1)24 T 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 
55 template<typename T>
f2(__restrict T x)56 void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}
57 
f3()58 void f3() {
59   f2<int*>(0);
60   f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
61 }
62