From a59775a17c7f9933f3d800557eb516a79ebe9bea Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 30 May 2016 15:10:51 +0000 Subject: [PATCH] re PR c++/71099 (Misleading diagnostic message with 'virtual' used in out-of-line definitions of class template member functions) /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. From-SVN: r236885 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/parser.c | 3 ++- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/parse/virtual1.C | 33 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/virtual1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b970c6ebae4..9b35abc66bc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +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'. + 2016-05-29 Paolo Carlini PR c++/71105 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2a46d6fbde7..c6c2c0cf948 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12888,7 +12888,8 @@ cp_parser_function_specifier_opt (cp_parser* parser, /* 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8abccad4129..6df7274fcfd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-30 Paolo Carlini + + PR c++/71099 + * g++.dg/parse/virtual1.C: New. + 2016-05-30 Uros Bizjak * gcc.target/i386/iamcu/args.h (clear_non_sret_int_hardware_registers): diff --git a/gcc/testsuite/g++.dg/parse/virtual1.C b/gcc/testsuite/g++.dg/parse/virtual1.C new file mode 100644 index 00000000000..1a5b995e34e --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/virtual1.C @@ -0,0 +1,33 @@ +// 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" } + +struct C { + template + virtual void foo(); // { dg-error "templates may not be 'virtual'" } +}; + +template +virtual void C::foo() {} // { dg-error "'virtual' outside class" } + +template +struct D { + template + virtual void foo(); // { dg-error "templates may not be 'virtual'" } +}; + +template +template +virtual void D::foo() {} // { dg-error "'virtual' outside class" } -- 2.30.2