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