Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Charles Li | e7cbb3e | 2015-11-17 20:25:05 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Sebastian Redl | 8d2ccae | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 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 | |
John McCall | e1ac8d1 | 2010-01-13 00:25:19 +0000 | [diff] [blame] | 13 | struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}} |
Charles Li | e7cbb3e | 2015-11-17 20:25:05 +0000 | [diff] [blame] | 14 | #if __cplusplus >= 201103L // C++11 or later |
| 15 | // expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}} |
| 16 | #endif |
Sebastian Redl | 8d2ccae | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 17 | |
Douglas Gregor | 4c95288 | 2009-08-24 21:39:56 +0000 | [diff] [blame] | 18 | template<typename T> |
| 19 | int f0(T x) { |
| 20 | return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2; |
| 21 | } |
| 22 | |
Sebastian Redl | 8d2ccae | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 23 | template <typename T, typename U> |
Douglas Gregor | 4c95288 | 2009-08-24 21:39:56 +0000 | [diff] [blame] | 24 | T f1(T t1, U u1, int i1) |
Sebastian Redl | 8d2ccae | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 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); |
Douglas Gregor | 4bbd1ac | 2009-10-17 21:40:42 +0000 | [diff] [blame] | 43 | new int(t1, u1); |
Sebastian Redl | 8d2ccae | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 44 | new (t1, u1) int; |
| 45 | delete t1; |
| 46 | |
Eli Friedman | 7827520 | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 47 | dummy d1 = sizeof(t1); // expected-error {{no viable conversion}} |
Douglas Gregor | a4b592a | 2009-12-19 03:01:41 +0000 | [diff] [blame] | 48 | dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}} |
Eli Friedman | 7827520 | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 49 | dummy d3 = __alignof(u1); // expected-error {{no viable conversion}} |
Chris Lattner | 24b8946 | 2010-09-05 00:17:29 +0000 | [diff] [blame] | 50 | i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}} |
Sebastian Redl | 8d2ccae | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 51 | |
| 52 | return u1; |
| 53 | } |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 54 | |
| 55 | template<typename T> |
Richard Smith | 89b466c | 2013-03-28 00:03:10 +0000 | [diff] [blame] | 56 | void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}} |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 57 | |
| 58 | void f3() { |
| 59 | f2<int*>(0); |
| 60 | f2<int>(0); // expected-error {{no matching function for call to 'f2'}} |
| 61 | } |