diff mbox

[2/2] Fix out-of-line definition of class template generic member functions.

Message ID 1393227162-26306-2-git-send-email-adam@jessamine.co.uk
State New
Headers show

Commit Message

Adam Butcher Feb. 24, 2014, 7:32 a.m. UTC
* parser.c (synthesize_implicit_template_parm): Inject new template
	argument list appropriately when a generic member function
	of a class template is declared out-of-line.

	* g++.dg/cpp1y/fn-generic-member-ool.C: New testcase.
---
 gcc/cp/parser.c                                    |  3 +-
 gcc/testsuite/g++.dg/cpp1y/fn-generic-member-ool.C | 35 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/fn-generic-member-ool.C
diff mbox

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 7e0531b..85b2f4b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -31906,7 +31906,8 @@  synthesize_implicit_template_parm  (cp_parser *parser)
 
       current_binding_level = scope;
 
-      if (scope->kind != sk_template_parms)
+      if (scope->kind != sk_template_parms
+	  || !function_being_declared_is_template_p (parser))
 	{
 	  /* Introduce a new template parameter list for implicit template
 	     parameters.  */
diff --git a/gcc/testsuite/g++.dg/cpp1y/fn-generic-member-ool.C b/gcc/testsuite/g++.dg/cpp1y/fn-generic-member-ool.C
new file mode 100644
index 0000000..f9c814e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/fn-generic-member-ool.C
@@ -0,0 +1,35 @@ 
+// Out-of-line generic member function definitions.
+// { dg-options "-std=c++1y" }
+
+struct A {
+  void f(auto x);
+};
+
+void A::f(auto x) {}  // injects a new list
+
+template <typename T>
+struct B {
+  void f(auto x);
+};
+
+template <typename T>
+void B<T>::f(auto x) {}  // injects a new list
+
+struct C {
+  template <int N>
+  void f(auto x);
+};
+
+template <int N>
+void C::f(auto x) {}  // extends existing inner list
+
+template <typename T>
+struct D
+{
+  template <int N>
+  void f(auto x);
+};
+
+template <typename T>
+template <int N>
+void D<T>::f(auto x) {}  // extends existing inner list