From 5243b51250b2107e3f645adf314fe95eaf9876d0 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 18 Dec 2015 18:18:47 +0000 Subject: [PATCH] /cp 2015-12-18 Paolo Carlini PR c++/67592 * decl.c (grokdeclarator): Reject constexpr virtual member functions; in error messages, prefer % and % to virtual and constexpr, respectively. /testsuite 2015-12-18 Paolo Carlini PR c++/67592 * g++.dg/cpp0x/constexpr-virtual5.C: New. * g++.dg/cpp0x/pr51463.C: Adjust dg-error string. * g++.dg/inherit/pure1.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231824 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 7 ++++++ gcc/cp/decl.c | 22 +++++++++++++------ gcc/testsuite/ChangeLog | 7 ++++++ .../g++.dg/cpp0x/constexpr-virtual5.C | 6 +++++ gcc/testsuite/g++.dg/cpp0x/pr51463.C | 2 +- gcc/testsuite/g++.dg/inherit/pure1.C | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 89c0a198a828..d471721f21c3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2015-12-18 Paolo Carlini + + PR c++/67592 + * decl.c (grokdeclarator): Reject constexpr virtual member functions; + in error messages, prefer % and % to virtual + and constexpr, respectively. + 2015-12-18 Patrick Palka PR c++/68831 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 7d45d4dc1f51..a14062bca0d2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9769,11 +9769,18 @@ grokdeclarator (const cp_declarator *declarator, if (storage_class == sc_static) staticp = 1 + (decl_context == FIELD); - if (virtualp && staticp == 2) + if (virtualp) { - error ("member %qD cannot be declared both virtual and static", dname); - storage_class = sc_none; - staticp = 0; + if (staticp == 2) + { + error ("member %qD cannot be declared both % " + "and %", dname); + storage_class = sc_none; + staticp = 0; + } + if (constexpr_p) + error ("member %qD cannot be declared both % " + "and %", dname); } friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend); @@ -10153,7 +10160,8 @@ grokdeclarator (const cp_declarator *declarator, explicitp = 2; if (virtualp) { - permerror (input_location, "constructors cannot be declared virtual"); + permerror (input_location, + "constructors cannot be declared %"); virtualp = 0; } if (decl_context == FIELD @@ -10988,7 +10996,7 @@ grokdeclarator (const cp_declarator *declarator, ARM 9.5 */ if (virtualp && TREE_CODE (ctype) == UNION_TYPE) { - error ("function %qD declared virtual inside a union", + error ("function %qD declared % inside a union", unqualified_id); return error_mark_node; } @@ -10997,7 +11005,7 @@ grokdeclarator (const cp_declarator *declarator, { if (virtualp) { - error ("%qD cannot be declared virtual, since it " + error ("%qD cannot be declared %, since it " "is always static", unqualified_id); virtualp = 0; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 57326d19ee9c..dabdceaff487 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2015-12-18 Paolo Carlini + + PR c++/67592 + * g++.dg/cpp0x/constexpr-virtual5.C: New. + * g++.dg/cpp0x/pr51463.C: Adjust dg-error string. + * g++.dg/inherit/pure1.C: Likewise. + 2015-12-18 Jeff Law PR rtl-optimization/49847 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C new file mode 100644 index 000000000000..895de506d674 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C @@ -0,0 +1,6 @@ +// PR c+++/67592 +// { dg-do compile { target c++11 } } + +struct S { + constexpr virtual int f() { return 1; } // { dg-error "both 'virtual' and 'constexpr'" } +}; diff --git a/gcc/testsuite/g++.dg/cpp0x/pr51463.C b/gcc/testsuite/g++.dg/cpp0x/pr51463.C index 6a57e47825cf..75de47d60e46 100644 --- a/gcc/testsuite/g++.dg/cpp0x/pr51463.C +++ b/gcc/testsuite/g++.dg/cpp0x/pr51463.C @@ -3,5 +3,5 @@ struct A { - static virtual int i = 0; // { dg-error "both virtual and static|declared as" } + static virtual int i = 0; // { dg-error "both 'virtual' and 'static'|declared as" } }; diff --git a/gcc/testsuite/g++.dg/inherit/pure1.C b/gcc/testsuite/g++.dg/inherit/pure1.C index e825f0098433..99a5767c787f 100644 --- a/gcc/testsuite/g++.dg/inherit/pure1.C +++ b/gcc/testsuite/g++.dg/inherit/pure1.C @@ -9,7 +9,7 @@ struct A { void foo2() = 0; // { dg-error "non-virtual" } static void foo3() = 0; // { dg-error "static member" } - virtual static void foo4() = 0; // { dg-error "both virtual and static" } + virtual static void foo4() = 0; // { dg-error "both 'virtual' and 'static'" } virtual void foo5() = 0; // { dg-error "base class" } }; -- 2.47.2