Re: [C++ Patch] PR 71109 ("Misleading diagnostic message with 'virtual' used in out-of-line definitions of class template member functions")

2016-05-30 Thread Jason Merrill
OK.

On Sun, May 29, 2016 at 6:49 PM, Paolo Carlini  wrote:
> Hi,
>
> submitter noticed that for wrong uses of 'virtual' outside of template
> classes (B in the testcase) vs plain classes (A) we wrongly emit the
> "templates may not be %" error message. Simply checking
> current_class_type seems enough to solve the problem. Case C in the extended
> testcase double checks that we still give the "templates may not be
> %" error message when appropriate. Tested x86_64-linux.
>
> Thanks,
> Paolo.
>
> //


[C++ Patch] PR 71109 ("Misleading diagnostic message with 'virtual' used in out-of-line definitions of class template member functions")

2016-05-29 Thread Paolo Carlini

Hi,

submitter noticed that for wrong uses of 'virtual' outside of template 
classes (B in the testcase) vs plain classes (A) we wrongly emit the 
"templates may not be %" error message. Simply checking 
current_class_type seems enough to solve the problem. Case C in the 
extended testcase double checks that we still give the "templates may 
not be %" error message when appropriate. Tested x86_64-linux.


Thanks,
Paolo.

//
/cp
2016-05-30  Paolo Carlini  

PR c++/71099
* parser.c (cp_parser_function_specifier_opt): Use current_class_type
to improve the diagnostic about wrong uses of 'virtual'.

/testsuite
2016-05-30  Paolo Carlini  

PR c++/71099
* g++.dg/parse/virtual1.C: New.
Index: cp/parser.c
===
--- cp/parser.c (revision 236863)
+++ cp/parser.c (working copy)
@@ -12888,7 +12888,8 @@ cp_parser_function_specifier_opt (cp_parser* parse
   /* 14.5.2.3 [temp.mem]
 
 A member function template shall not be virtual.  */
-  if (PROCESSING_REAL_TEMPLATE_DECL_P ())
+  if (PROCESSING_REAL_TEMPLATE_DECL_P ()
+ && current_class_type)
error_at (token->location, "templates may not be %");
   else
set_and_check_decl_spec_loc (decl_specs, ds_virtual, token);
Index: testsuite/g++.dg/parse/virtual1.C
===
--- testsuite/g++.dg/parse/virtual1.C   (revision 0)
+++ testsuite/g++.dg/parse/virtual1.C   (working copy)
@@ -0,0 +1,25 @@
+// PR c++/71099
+
+struct A {
+  virtual void foo();
+};
+
+virtual void A::foo() {}  // { dg-error "'virtual' outside class" }
+
+template
+struct B {
+  virtual void foo();
+};
+
+template
+virtual void B::foo() {}  // { dg-error "'virtual' outside class" }
+
+template
+struct C {
+  template
+  virtual void foo();  // { dg-error "templates may not be 'virtual'" }
+};
+
+template
+template
+virtual void C::foo() {}  // { dg-error "'virtual' outside class" }