aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/template
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/template')
-rw-r--r--gcc/testsuite/g++.dg/template/access7.C18
-rw-r--r--gcc/testsuite/g++.dg/template/alignof1.C13
-rw-r--r--gcc/testsuite/g++.dg/template/conv5.C22
-rw-r--r--gcc/testsuite/g++.dg/template/friend10.C45
-rw-r--r--gcc/testsuite/g++.dg/template/friend12.C24
-rw-r--r--gcc/testsuite/g++.dg/template/friend13.C21
-rw-r--r--gcc/testsuite/g++.dg/template/friend14.C20
-rw-r--r--gcc/testsuite/g++.dg/template/friend15.C19
-rw-r--r--gcc/testsuite/g++.dg/template/friend16.C16
-rw-r--r--gcc/testsuite/g++.dg/template/friend9.C18
-rw-r--r--gcc/testsuite/g++.dg/template/nested2.C9
-rw-r--r--gcc/testsuite/g++.dg/template/ntp2.C16
-rw-r--r--gcc/testsuite/g++.dg/template/op1.C12
-rw-r--r--gcc/testsuite/g++.dg/template/ptrmem4.C20
-rw-r--r--gcc/testsuite/g++.dg/template/static3.C25
-rw-r--r--gcc/testsuite/g++.dg/template/ttp3.C2
-rw-r--r--gcc/testsuite/g++.dg/template/type2.C16
-rw-r--r--gcc/testsuite/g++.dg/template/typename3.C2
-rw-r--r--gcc/testsuite/g++.dg/template/unify4.C18
19 files changed, 334 insertions, 2 deletions
diff --git a/gcc/testsuite/g++.dg/template/access7.C b/gcc/testsuite/g++.dg/template/access7.C
new file mode 100644
index 00000000000..92d4c68db39
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/access7.C
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+// PR c++/3663
+// Enforce access of nested type.
+
+template <typename A>
+class S {
+ class T {}; // { dg-error "private" }
+};
+
+template <typename A>
+typename A::T* f (A) { // { dg-error "this context" }
+ return 0;
+}
+
+void g () {
+ f (S<int> ()); // { dg-error "context|instantiated" }
+}
diff --git a/gcc/testsuite/g++.dg/template/alignof1.C b/gcc/testsuite/g++.dg/template/alignof1.C
new file mode 100644
index 00000000000..50a32183cfc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/alignof1.C
@@ -0,0 +1,13 @@
+template<typename T>
+int my_alignof()
+{
+ return __alignof__(T);
+}
+
+template<typename>
+struct X { };
+
+int main()
+{
+ return my_alignof<X<void> >();
+}
diff --git a/gcc/testsuite/g++.dg/template/conv5.C b/gcc/testsuite/g++.dg/template/conv5.C
new file mode 100644
index 00000000000..80835437a98
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/conv5.C
@@ -0,0 +1,22 @@
+// { dg-do compile }
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Dec 2002 <nathan@codesourcery.com>
+
+// PR 764. Failed to find friend in overload resolution
+
+template <class T>
+struct S
+{
+ friend bool operator== (const S&, const S&) {
+ return true;
+ }
+};
+
+int main ()
+{
+ // S<int> s;
+
+ const S<int> *p = 0;
+ *p == *p; // error
+}
diff --git a/gcc/testsuite/g++.dg/template/friend10.C b/gcc/testsuite/g++.dg/template/friend10.C
new file mode 100644
index 00000000000..cab5e346f0b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend10.C
@@ -0,0 +1,45 @@
+// { dg-do run }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com>
+
+// PR 5116. template instantiation can add a friend into a namespace,
+// and thus change overload resolution.
+
+#include <iostream>
+
+static int right;
+static int wrong;
+
+struct Buggy {};
+
+template <typename T>struct Handle
+{
+ Handle(T* p) {}
+
+ operator bool() const { wrong++; return true; }
+
+ friend std::ostream& operator<<(std::ostream& ostr, const Handle& r)
+ {
+ right++;
+
+ return ostr << "in operator<<(ostream&, const Handle&)";
+ }
+};
+
+typedef Handle<Buggy> Buggy_h;
+
+bool cmp (const Buggy_h& b1, const Buggy_h& b2)
+{
+ std::cout << b1 << " " << b2 << std::endl;
+ return false;
+}
+
+int main()
+{
+ Buggy o;
+
+ cmp (&o, &o);
+
+ return !(right == 2 && !wrong);
+}
diff --git a/gcc/testsuite/g++.dg/template/friend12.C b/gcc/testsuite/g++.dg/template/friend12.C
new file mode 100644
index 00000000000..0cd561b5a2a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend12.C
@@ -0,0 +1,24 @@
+// { dg-do compile }
+
+// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+// PR 9030. Perform access checking to parameter and return type of
+// function template correctly when the template is friend.
+
+template <class T> class Outer {
+ private:
+ struct Inner {};
+
+ template <class T_>
+ friend typename Outer<T_>::Inner foo ();
+};
+
+template <class T>
+typename Outer<T>::Inner
+foo () {
+ return typename Outer<T>::Inner();
+}
+
+void f() {
+ foo<int>();
+}
diff --git a/gcc/testsuite/g++.dg/template/friend13.C b/gcc/testsuite/g++.dg/template/friend13.C
new file mode 100644
index 00000000000..6eebf6b951f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend13.C
@@ -0,0 +1,21 @@
+// { dg-do compile }
+
+// Perform access checking to parameter and return type of
+// function template correctly when only specialization is friend.
+
+template <class T>
+typename T::Inner
+foo () {
+ return typename T::Inner();
+}
+
+class Outer {
+ private:
+ struct Inner {};
+
+ friend Outer::Inner foo<Outer> ();
+};
+
+void f() {
+ foo<Outer>();
+}
diff --git a/gcc/testsuite/g++.dg/template/friend14.C b/gcc/testsuite/g++.dg/template/friend14.C
new file mode 100644
index 00000000000..6e07b98932a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend14.C
@@ -0,0 +1,20 @@
+// { dg-do compile }
+
+// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+// Perform access checking to parameter and return type of
+// function template correctly when the template is friend.
+
+template <class T> class O {
+ struct I { I (int); };
+
+ template <class T_>
+ friend typename O<T_>::I f ();
+};
+
+template <class T_>
+typename O<T_>::I f () { return 1; }
+
+struct X {
+ void g() { f<int>(); }
+};
diff --git a/gcc/testsuite/g++.dg/template/friend15.C b/gcc/testsuite/g++.dg/template/friend15.C
new file mode 100644
index 00000000000..4acbf2d1a56
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend15.C
@@ -0,0 +1,19 @@
+// { dg-do compile }
+
+// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+// PR c++/9453
+// Access checking when template friend is defined in class.
+
+template <typename> class X {
+ private:
+ struct Inner;
+
+ template <typename R>
+ friend typename X<R>::Inner * foo () { return 0; }
+};
+template class X<void>;
+
+struct U {
+ void bar () { foo<void> (); }
+};
diff --git a/gcc/testsuite/g++.dg/template/friend16.C b/gcc/testsuite/g++.dg/template/friend16.C
new file mode 100644
index 00000000000..3165ed2b59d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend16.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+
+// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+// PR c++/9602: Inline friend/pure virtual tree data sharing in
+// class template.
+
+template <typename T> struct X {
+ void foo (X);
+ friend void bar () {}
+};
+
+template <typename T>
+void X<T>::foo (X x) {}
+
+template struct X<int>;
diff --git a/gcc/testsuite/g++.dg/template/friend9.C b/gcc/testsuite/g++.dg/template/friend9.C
new file mode 100644
index 00000000000..4464e5f8ee8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend9.C
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+// PR c++/8099
+// Partial specialization as friend class
+
+template <int N, typename T> struct X;
+template <typename T> struct X<1,T>;
+
+template <typename P> class Y {
+ static int i;
+ template <int N, typename T> friend struct X;
+ friend struct X<1,P>;
+};
+
+template <typename T> struct X<1,T> {
+ X () { Y<T>::i; }; // access private field
+};
diff --git a/gcc/testsuite/g++.dg/template/nested2.C b/gcc/testsuite/g++.dg/template/nested2.C
new file mode 100644
index 00000000000..be4f95f716d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/nested2.C
@@ -0,0 +1,9 @@
+template <class T> class CO {
+ class CI1 {
+ class CI2;
+ };
+};
+
+template <class T>
+class CO<T>::CI1::CI2 {};
+
diff --git a/gcc/testsuite/g++.dg/template/ntp2.C b/gcc/testsuite/g++.dg/template/ntp2.C
new file mode 100644
index 00000000000..42219e0fcb0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ntp2.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Dec 2002 <nathan@codesourcery.com>
+
+// PR 3784: We were confusing non-type template parms.
+
+template <unsigned N> class X { };
+
+template <short N> void foo1(X<N>);
+template <unsigned N> void foo2(X<N>);
+
+int main() {
+ X<2> x;
+ foo2(x);
+}
diff --git a/gcc/testsuite/g++.dg/template/op1.C b/gcc/testsuite/g++.dg/template/op1.C
new file mode 100644
index 00000000000..7cc9c9e91c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/op1.C
@@ -0,0 +1,12 @@
+template <class T> struct X {
+ typedef int type;
+};
+
+template <class T> struct O {
+ struct I {
+ operator typename X<T>::type ();
+ };
+};
+
+template <class T>
+O<T>::I::operator typename X<T>::type () {}
diff --git a/gcc/testsuite/g++.dg/template/ptrmem4.C b/gcc/testsuite/g++.dg/template/ptrmem4.C
new file mode 100644
index 00000000000..23107286913
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ptrmem4.C
@@ -0,0 +1,20 @@
+// { dg-do compile }
+
+// Origin: Scott Snyder <snyder@fnal.gov>
+
+// PR c++/8849
+// Pointer to member function template argument deduction ICE.
+
+
+template <class CONT> void queryAliases(CONT& fill_me); // { dg-error "argument" }
+
+struct SpyExample
+{
+ void ready();
+ void inputs();
+};
+
+void SpyExample::ready()
+{
+ queryAliases(inputs); // { dg-error "convert" }
+}
diff --git a/gcc/testsuite/g++.dg/template/static3.C b/gcc/testsuite/g++.dg/template/static3.C
new file mode 100644
index 00000000000..65cf2c9e7b2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/static3.C
@@ -0,0 +1,25 @@
+template <class data> class foo
+{
+ public:
+ static const int a;
+ static const int b;
+ static const int c;
+ static const int d;
+};
+
+template <class data> const int foo<data>::a = 1;
+template <class data> const int foo<data>::b = a;
+template <class data> const int foo<data>::c = b;
+template <class data> const int foo<data>::d = c;
+
+typedef foo<int> fooInt;
+
+int main( void )
+{
+ fooInt *f;
+
+ f = new fooInt();
+
+ if (f->c != 1 || f->d != 1)
+ return 1;
+}
diff --git a/gcc/testsuite/g++.dg/template/ttp3.C b/gcc/testsuite/g++.dg/template/ttp3.C
index 05bd44a172e..fe9bd9eb382 100644
--- a/gcc/testsuite/g++.dg/template/ttp3.C
+++ b/gcc/testsuite/g++.dg/template/ttp3.C
@@ -14,7 +14,7 @@ class OUTER {
template <class T>
class List { };
- vector<class List> data; // { dg-error "type/value mismatch|expected a type|ISO C" "" }
+ vector<class List> data; // { dg-error "argument is required|ISO C" "" }
};
template <class T>
diff --git a/gcc/testsuite/g++.dg/template/type2.C b/gcc/testsuite/g++.dg/template/type2.C
new file mode 100644
index 00000000000..509c4820d6b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/type2.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// Origin: Juan Carlos Arevalo-Baeza <jcab@JCABs-Rumblings.com>
+
+// PR c++/8442
+// Type template parameter incorrectly treated as template template
+// parameter.
+
+template <typename T> struct A {};
+
+template <typename T> struct B
+{
+ template <typename U> struct C {};
+ template <typename U> A<C<U> > foo(U);
+};
+
+B<void> b;
diff --git a/gcc/testsuite/g++.dg/template/typename3.C b/gcc/testsuite/g++.dg/template/typename3.C
index 1c573baa0df..a9a914286a9 100644
--- a/gcc/testsuite/g++.dg/template/typename3.C
+++ b/gcc/testsuite/g++.dg/template/typename3.C
@@ -3,5 +3,5 @@
template <class A>
struct B {
- typedef A::C::D E; // { dg-error "no type|parse error" }
+ typedef A::C::D E; // { dg-error "no type|(parse|syntax) error" }
};
diff --git a/gcc/testsuite/g++.dg/template/unify4.C b/gcc/testsuite/g++.dg/template/unify4.C
new file mode 100644
index 00000000000..19d9f3a9f03
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/unify4.C
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 28 Jan 2003 <nathan@codesourcery.com>
+
+// PR 9437. We'd unify 'T *' with 'U C::*', which is obviously broken
+
+struct X
+{
+ template <typename T>
+ operator T* () const { return static_cast<T*> (0); }
+} null;
+
+struct A { int i; };
+
+static void f (int A::* pmi) { }
+
+int main () { f (null); } // { dg-error "cannot convert" "" }