aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2016-05-30 15:10:51 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2016-05-30 15:10:51 +0000
commita59775a17c7f9933f3d800557eb516a79ebe9bea (patch)
treec7c23ee68d8ebf6073ebdc1d427674d032309edb /gcc
parent53d6d955606658b7fe0bb9356ad9d7191b61742c (diff)
downloadgcc-a59775a17c7f9933f3d800557eb516a79ebe9bea.zip
gcc-a59775a17c7f9933f3d800557eb516a79ebe9bea.tar.gz
gcc-a59775a17c7f9933f3d800557eb516a79ebe9bea.tar.bz2
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 <paolo.carlini@oracle.com> 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 <paolo.carlini@oracle.com> PR c++/71099 * g++.dg/parse/virtual1.C: New. From-SVN: r236885
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/virtual1.C33
4 files changed, 46 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b970c6e..9b35abc 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2016-05-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ 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 <paolo.carlini@oracle.com>
PR c++/71105
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 2a46d6f..c6c2c0c 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 %<virtual%>");
else
set_and_check_decl_spec_loc (decl_specs, ds_virtual, token);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8abccad..6df7274 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/71099
+ * g++.dg/parse/virtual1.C: New.
+
2016-05-30 Uros Bizjak <ubizjak@gmail.com>
* 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 0000000..1a5b995
--- /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<typename>
+struct B {
+ virtual void foo();
+};
+
+template<typename T>
+virtual void B<T>::foo() {} // { dg-error "'virtual' outside class" }
+
+struct C {
+ template<typename>
+ virtual void foo(); // { dg-error "templates may not be 'virtual'" }
+};
+
+template<typename>
+virtual void C::foo() {} // { dg-error "'virtual' outside class" }
+
+template<typename>
+struct D {
+ template<typename>
+ virtual void foo(); // { dg-error "templates may not be 'virtual'" }
+};
+
+template<typename T>
+template<typename>
+virtual void D<T>::foo() {} // { dg-error "'virtual' outside class" }