Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 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 | |
John McCall | 220ccbf | 2010-01-13 00:25:19 +0000 | [diff] [blame] | 11 | struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}} |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 12 | |
Douglas Gregor | 9983cc1 | 2009-08-24 21:39:56 +0000 | [diff] [blame] | 13 | template<typename T> |
| 14 | int f0(T x) { |
| 15 | return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2; |
| 16 | } |
| 17 | |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 18 | template <typename T, typename U> |
Douglas Gregor | 9983cc1 | 2009-08-24 21:39:56 +0000 | [diff] [blame] | 19 | T f1(T t1, U u1, int i1) |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 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); |
Douglas Gregor | 089407b | 2009-10-17 21:40:42 +0000 | [diff] [blame] | 38 | new int(t1, u1); |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 39 | new (t1, u1) int; |
| 40 | delete t1; |
| 41 | |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 42 | dummy d1 = sizeof(t1); // expected-error {{no viable conversion}} |
Douglas Gregor | 7abfbdb | 2009-12-19 03:01:41 +0000 | [diff] [blame] | 43 | dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}} |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 44 | dummy d3 = __alignof(u1); // expected-error {{no viable conversion}} |
Chris Lattner | 0c42bb6 | 2010-09-05 00:17:29 +0000 | [diff] [blame] | 45 | i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}} |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 46 | |
| 47 | return u1; |
| 48 | } |
Richard Smith | 9807a2e | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 49 | |
| 50 | template<typename T> |
Richard Smith | 93d6b07 | 2013-03-28 00:03:10 +0000 | [diff] [blame] | 51 | void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}} |
Richard Smith | 9807a2e | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 52 | |
| 53 | void f3() { |
| 54 | f2<int*>(0); |
| 55 | f2<int>(0); // expected-error {{no matching function for call to 'f2'}} |
| 56 | } |