File: instantiate-template-template-parm.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (97 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download | duplicates (32)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<template<typename T> class MetaFun, typename Value>
struct apply {
  typedef typename MetaFun<Value>::type type;
};

template<class T>
struct add_pointer {
  typedef T* type;
};

template<class T>
struct add_reference {
  typedef T& type;
};

int i;
apply<add_pointer, int>::type ip = &i;
apply<add_reference, int>::type ir = i;
apply<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}}

// Template template parameters
template<int> struct B; // expected-note{{has a different type 'int'}}

template<typename T, 
         template<T Value> class X> // expected-error{{cannot have type 'float'}} \
                                    // expected-note{{with type 'long'}}
struct X0 { };

X0<int, B> x0b1;
X0<float, B> x0b2; // expected-note{{while substituting}}
X0<long, B> x0b3; // expected-error{{template template argument has different template parameters}}

template<template<int V> class TT> // expected-note{{parameter with type 'int'}}
struct X1 { };

template<typename T, template<T V> class TT>
struct X2 {
  X1<TT> x1; // expected-error{{has different template parameters}}
};

template<int V> struct X3i { };
template<long V> struct X3l { }; // expected-note{{different type 'long'}}

X2<int, X3i> x2okay;
X2<long, X3l> x2bad; // expected-note{{instantiation}}

template <typename T, template <T, T> class TT, class R = TT<1, 2> >
struct Comp {
  typedef R r1;
  template <T x, T y> struct gt {
    static const bool result = x > y;
  };
  typedef gt<2, 1> r2;
};

template <int x, int y> struct lt {
  static const bool result = x < y;
};

Comp<int, lt> c0;

namespace PR8629 {
  template<template<int> class TT> struct X0
  {
    static void apply();
  };
  template<int> struct Type { };

  template<class T> struct X1
  {
    template<class U> struct Inner;

    template<class U> void g()
    {
      typedef Inner<U> Init;
      X0<Init::template VeryInner>::apply();
    }
    template<int N> void f ()
    {
      g<Type<N> >();
    }
  };
  template<class T> template<class U> struct X1<T>::Inner
  {
    template<int> struct VeryInner {
    };
  };
  struct X1Container
  {
    X1Container()
    {
      simplex_.f<0>();
    }
    X1<double> simplex_;
  };
}