blob: 4d8aaa8d16f1e50d609d95e28b180425b8c6aa35 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -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
11struct dummy {};
12
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
Douglas Gregor9ea62762009-05-21 23:17:49 +000042 dummy d1 = sizeof(t1); // FIXME: delayed checking okay?
Sebastian Redl28507842009-02-26 14:39:58 +000043 dummy d2 = offsetof(T, foo); // expected-error {{cannot initialize 'd2'}}
Douglas Gregor9ea62762009-05-21 23:17:49 +000044 dummy d3 = __alignof(u1); // FIXME: delayed checking okay?
Sebastian Redl28507842009-02-26 14:39:58 +000045 i1 = typeid(t1); // expected-error {{incompatible type assigning}}
46
47 return u1;
48}