T foo(T t);
template <>
-int foo<char>(char c); // ERROR - bad return type.
+int foo<char>(char c); // ERROR - does not match any template declaration
// Build don't link:
// GROUPS passed templates
template <class T, class U>
-T foo(T t, U* u);
+T foo(T t, U* u); // ERROR - template candidate
template <class T>
-T foo(T t, T* t);
+T foo(T t, T* t); // ERROR - template candidate
template <>
-int foo<int>(int, int*); // ERROR - ambiguous specialization.
+int foo<int>(int, int*); // ERROR - ambiguous template specialization
template <class T>
void f(T)
{
+ int j;
+
+ j = 6;
+
struct S {
int i;
};
S s;
- s.i = 3;
+ s.i = j;
- if (s.i != 3)
+ if (s.i != 6)
abort();
}
struct S
{
template <class T>
- void foo(T);
+ void foo(T) {}
};
template void S::foo(int);
--- /dev/null
+// Build don't link:
+
+template <class T>
+struct S1 {};
+
+template <class T>
+void f(T);
+
+template <class C>
+struct S2
+{
+ template <class T>
+ void f<S1<T> >(T) {} // ERROR - bad specialization.
+};
+
+
+template <class T>
+struct S3
+{
+ friend class S2<T>;
+};
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+struct S
+{
+ template <class U>
+ int f(U u);
+};
+
+
+template <class T>
+template <>
+int S<T>::f<int>(int i) { return 1; }
+
+int main()
+{
+ S<char> sc;
+
+ if (sc.f(3) != 1)
+ abort();
+}
--- /dev/null
+template <class T>
+void f(T t);
+
+template <class T>
+void f(T* t);
+
+template <>
+void f(int* ip) {}
+
+struct S1
+{
+ template <class T>
+ void f(T t);
+
+ template <class T>
+ void f(T* t);
+
+ template <>
+ void f(int* ip) {}
+};
+
+template <class U>
+struct S2
+{
+ template <class T>
+ void f(T t);
+
+ template <class T>
+ void f(T* t);
+
+ template <>
+ void f(int* ip) {}
+};
+
+int main()
+{
+ int* ip;
+ S1 s1;
+ s1.f(ip);
+ S2<double> s2;
+ s2.f(ip);
+}