blob: 2d515b4b155ade7e833dccd38dbf77ecdae7ae38 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Sebastian Redl28507842009-02-26 14:39:58 +00002
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.
9namespace std { class type_info {}; }
10
John McCall220ccbf2010-01-13 00:25:19 +000011struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
Sebastian Redl28507842009-02-26 14:39:58 +000012
Douglas Gregor9983cc12009-08-24 21:39:56 +000013template<typename T>
14int f0(T x) {
15 return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;
16}
17
Sebastian Redl28507842009-02-26 14:39:58 +000018template <typename T, typename U>
Douglas Gregor9983cc12009-08-24 21:39:56 +000019T f1(T t1, U u1, int i1)
Sebastian Redl28507842009-02-26 14:39:58 +000020{
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);
Douglas Gregor089407b2009-10-17 21:40:42 +000038 new int(t1, u1);
Sebastian Redl28507842009-02-26 14:39:58 +000039 new (t1, u1) int;
40 delete t1;
41
Eli Friedmancfdc81a2009-12-19 08:11:05 +000042 dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}
Douglas Gregor7abfbdb2009-12-19 03:01:41 +000043 dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}
Eli Friedmancfdc81a2009-12-19 08:11:05 +000044 dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}
Chris Lattner0c42bb62010-09-05 00:17:29 +000045 i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}}
Sebastian Redl28507842009-02-26 14:39:58 +000046
47 return u1;
48}
Richard Smith9807a2e2013-03-27 23:36:39 +000049
50template<typename T>
Richard Smith93d6b072013-03-28 00:03:10 +000051void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}
Richard Smith9807a2e2013-03-27 23:36:39 +000052
53void f3() {
54 f2<int*>(0);
55 f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
56}