summaryrefslogtreecommitdiff
path: root/clang/test/SemaTemplate/instantiate-template-template-parm.cpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
commitbe1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch)
tree1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/SemaTemplate/instantiate-template-template-parm.cpp
parentc4626a62754862d20b41e8a46a3574264ea80e6d (diff)
parentf1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaTemplate/instantiate-template-template-parm.cpp')
-rw-r--r--clang/test/SemaTemplate/instantiate-template-template-parm.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/instantiate-template-template-parm.cpp b/clang/test/SemaTemplate/instantiate-template-template-parm.cpp
new file mode 100644
index 0000000..a70c7e8
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-template-template-parm.cpp
@@ -0,0 +1,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_;
+ };
+}