xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/instantiate-function-2.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc template <typename T> struct S {
3*f4a2713aSLionel Sambuc   S() { }
4*f4a2713aSLionel Sambuc   S(T t);
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc template struct S<int>;
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc void f() {
10*f4a2713aSLionel Sambuc   S<int> s1;
11*f4a2713aSLionel Sambuc   S<int> s2(10);
12*f4a2713aSLionel Sambuc }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc namespace PR7184 {
15*f4a2713aSLionel Sambuc   template<typename T>
16*f4a2713aSLionel Sambuc   void f() {
17*f4a2713aSLionel Sambuc     typedef T type;
18*f4a2713aSLionel Sambuc     void g(int array[sizeof(type)]);
19*f4a2713aSLionel Sambuc   }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc   template void f<int>();
22*f4a2713aSLionel Sambuc }
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc namespace UsedAttr {
25*f4a2713aSLionel Sambuc   template<typename T>
26*f4a2713aSLionel Sambuc   void __attribute__((used)) foo() {
27*f4a2713aSLionel Sambuc     T *x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
28*f4a2713aSLionel Sambuc   }
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc   void bar() {
31*f4a2713aSLionel Sambuc     foo<int>(); // expected-note{{instantiation of}}
32*f4a2713aSLionel Sambuc   }
33*f4a2713aSLionel Sambuc }
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc namespace PR9654 {
36*f4a2713aSLionel Sambuc   typedef void ftype(int);
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc   template<typename T>
39*f4a2713aSLionel Sambuc   ftype f;
40*f4a2713aSLionel Sambuc 
41*f4a2713aSLionel Sambuc   void g() {
42*f4a2713aSLionel Sambuc     f<int>(0);
43*f4a2713aSLionel Sambuc   }
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc namespace AliasTagDef {
47*f4a2713aSLionel Sambuc   template<typename T>
48*f4a2713aSLionel Sambuc   T f() {
49*f4a2713aSLionel Sambuc     using S = struct { // expected-warning {{C++11}}
50*f4a2713aSLionel Sambuc       T g() {
51*f4a2713aSLionel Sambuc         return T();
52*f4a2713aSLionel Sambuc       }
53*f4a2713aSLionel Sambuc     };
54*f4a2713aSLionel Sambuc     return S().g();
55*f4a2713aSLionel Sambuc   }
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc   int n = f<int>();
58*f4a2713aSLionel Sambuc }
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc namespace PR10273 {
61*f4a2713aSLionel Sambuc   template<typename T> void (f)(T t) {}
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc   void g() {
64*f4a2713aSLionel Sambuc     (f)(17);
65*f4a2713aSLionel Sambuc   }
66*f4a2713aSLionel Sambuc }
67