* [C++ Patch] PR 67592 ("A virtual member function declared constexpr fails to trigger a diagnostic")
@ 2015-12-18 14:05 Paolo Carlini
2015-12-18 17:57 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2015-12-18 14:05 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
Hi,
a simple issue: we fail to reject such declarations. While working on
it, I noticed a tad of inconsistency in our error messages, where we
have a mix of, eg, "... declared %<virtual%>..." and "... declared
virtual...". I think we should prefer the former and spotted a few
places needing adjustment. Tested x86_64-linux.
Thanks,
Paolo.
/////////////////////
[-- Attachment #2: CL_67592 --]
[-- Type: text/plain, Size: 454 bytes --]
/cp
2015-12-18 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/67592
* decl.c (grokdeclarator): Reject constexpr virtual member functions;
in error messages, prefer %<virtual%> and %<constexpr%> to virtual
and constexpr, respectively.
/testsuite
2015-12-18 Paolo Carlini <paolo.carlini@oracle.com>
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.
[-- Attachment #3: patch_67592 --]
[-- Type: text/plain, Size: 3300 bytes --]
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 231814)
+++ cp/decl.c (working copy)
@@ -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 %<virtual%> "
+ "and %<static%>", dname);
+ storage_class = sc_none;
+ staticp = 0;
+ }
+ if (constexpr_p)
+ error ("member %qD cannot be declared both %<virtual%> "
+ "and %<constexpr%>", 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 %<virtual%>");
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 %<virtual%> 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 %<virtual%>, since it "
"is always static",
unqualified_id);
virtualp = 0;
Index: testsuite/g++.dg/cpp0x/constexpr-virtual5.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-virtual5.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-virtual5.C (working copy)
@@ -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'" }
+};
Index: testsuite/g++.dg/cpp0x/pr51463.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr51463.C (revision 231814)
+++ testsuite/g++.dg/cpp0x/pr51463.C (working copy)
@@ -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" }
};
Index: testsuite/g++.dg/inherit/pure1.C
===================================================================
--- testsuite/g++.dg/inherit/pure1.C (revision 231814)
+++ testsuite/g++.dg/inherit/pure1.C (working copy)
@@ -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" }
};
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ Patch] PR 67592 ("A virtual member function declared constexpr fails to trigger a diagnostic")
2015-12-18 14:05 [C++ Patch] PR 67592 ("A virtual member function declared constexpr fails to trigger a diagnostic") Paolo Carlini
@ 2015-12-18 17:57 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-12-18 17:57 UTC (permalink / raw)
To: Paolo Carlini, gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-18 17:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-18 14:05 [C++ Patch] PR 67592 ("A virtual member function declared constexpr fails to trigger a diagnostic") Paolo Carlini
2015-12-18 17:57 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).