blob: 037747d35c0de32d0e8b36cca3fcc1ceb3f6a070 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Charles Lie7cbb3e2015-11-17 20:25:05 +00002// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Sebastian Redl8d2ccae2009-02-26 14:39:58 +00004
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.
11namespace std { class type_info {}; }
12
John McCalle1ac8d12010-01-13 00:25:19 +000013struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
Charles Lie7cbb3e2015-11-17 20:25:05 +000014#if __cplusplus >= 201103L // C++11 or later
15// expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}
16#endif
Sebastian Redl8d2ccae2009-02-26 14:39:58 +000017
Douglas Gregor4c952882009-08-24 21:39:56 +000018template<typename T>
19int f0(T x) {
20 return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;
21}
22
Sebastian Redl8d2ccae2009-02-26 14:39:58 +000023template <typename T, typename U>
Douglas Gregor4c952882009-08-24 21:39:56 +000024T f1(T t1, U u1, int i1)
Sebastian Redl8d2ccae2009-02-26 14:39:58 +000025{
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 Gregor4bbd1ac2009-10-17 21:40:42 +000043 new int(t1, u1);
Sebastian Redl8d2ccae2009-02-26 14:39:58 +000044 new (t1, u1) int;
45 delete t1;
46
Eli Friedman78275202009-12-19 08:11:05 +000047 dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}
Douglas Gregora4b592a2009-12-19 03:01:41 +000048 dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}
Eli Friedman78275202009-12-19 08:11:05 +000049 dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}
Chris Lattner24b89462010-09-05 00:17:29 +000050 i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}}
Sebastian Redl8d2ccae2009-02-26 14:39:58 +000051
52 return u1;
53}
Richard Smithdeec0742013-03-27 23:36:39 +000054
55template<typename T>
Richard Smith89b466c2013-03-28 00:03:10 +000056void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}
Richard Smithdeec0742013-03-27 23:36:39 +000057
58void f3() {
59 f2<int*>(0);
60 f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
61}