fun-template-def.cpp revision 2850784bda09416fc7e9d57f5baa36c9351c757c
1// RUN: clang -fsyntax-only -verify %s 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. 9namespace std { class type_info {}; } 10 11struct dummy {}; 12 13template <typename T, typename U> 14T f(T t1, U u1, int i1) 15{ 16 T t2 = i1; 17 t2 = i1 + u1; 18 ++u1; 19 u1++; 20 int i2 = u1; 21 22 i1 = t1[u1]; 23 i1 *= t1; 24 25 i1(u1, t1); // error 26 u1(i1, t1); 27 28 U u2 = (T)i1; 29 static_cast<void>(static_cast<U>(reinterpret_cast<T>( 30 dynamic_cast<U>(const_cast<T>(i1))))); 31 32 new U(i1, t1); 33 new int(t1, u1); // expected-error {{initializer of a builtin type can only take one argument}} 34 new (t1, u1) int; 35 delete t1; 36 37 dummy d1 = sizeof(t1); // expected-error {{cannot initialize 'd1'}} 38 dummy d2 = offsetof(T, foo); // expected-error {{cannot initialize 'd2'}} 39 dummy d3 = __alignof(u1); // expected-error {{cannot initialize 'd3'}} 40 i1 = typeid(t1); // expected-error {{incompatible type assigning}} 41 42 return u1; 43} 44