[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaTemplate / fun-template-def.cpp
blobde77901b5b601fdfd2498dac89b317f853fa9077
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 // Tests that dependent expressions are always allowed, whereas non-dependent
6 // are checked as usual.
8 #include <stddef.h>
10 // Fake typeid, lacking a typeinfo header.
11 namespace std { class type_info {}; }
13 struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
14 #if __cplusplus >= 201103L // C++11 or later
15 // expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}
16 #endif
18 template<typename T>
19 int f0(T x) {
20 return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;
23 template <typename T, typename U>
24 T f1(T t1, U u1, int i1, T** tpp)
26 T t2 = i1;
27 t2 = i1 + u1;
28 ++u1;
29 u1++;
30 int i2 = u1;
32 i1 = t1[u1];
33 i1 *= t1;
35 i1(u1, t1); // error
36 u1(i1, t1);
38 U u2 = (T)i1;
39 static_cast<void>(static_cast<U>(reinterpret_cast<T>(
40 dynamic_cast<U>(const_cast<T>(i1)))));
42 new U(i1, t1);
43 new int(t1, u1);
44 new (t1, u1) int;
45 delete t1;
47 dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}
48 dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}
49 dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}
50 i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}}
51 i1 = tpp[0].size(); // expected-error {{'T *' is not a structure or union}}
53 return u1;
56 template<typename T>
57 void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}
59 void f3() {
60 f2<int*>(0);
61 f2<int>(0); // expected-error {{no matching function for call to 'f2'}}