* [C++ PATCH] Avoid ICE on invalid struct A { friend int A () {} } (PR c++/34488)
@ 2007-12-17 15:11 Jakub Jelinek
2007-12-17 16:42 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2007-12-17 15:11 UTC (permalink / raw)
To: Mark Mitchell, Jason Merrill; +Cc: gcc-patches
Hi!
The following ICE on invalid was introduced by
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123312 (PR29077 fix),
where we now mark a decl with DECL_CONSTRUCTOR_P much earlier than we did
before and for invalid unqualified friend sfk_constructor this means ICE.
Similar invalid struct A { friend int ~A () {} }; doesn't crash since the
PR22293 fix, this patch fixes the constructor case similarly. AFAIK the
only valid constructor in friend should be a qualified one, which will have
METHOD_TYPE, rather than FUNCTION_TYPE as in this invalid case.
Regtested on x86_64-linux, ok for trunk?
2007-12-17 Jakub Jelinek <jakub@redhat.com>
PR c++/34488
* decl.c (grokdeclarator): Reject friend sfk_constructor
FUNCTION_TYPE.
* g++.dg/parse/friend7.C: New test.
--- gcc/cp/decl.c.jj 2007-11-26 22:14:07.000000000 +0100
+++ gcc/cp/decl.c 2007-12-17 14:56:49.000000000 +0100
@@ -8818,6 +8818,13 @@ grokdeclarator (const cp_declarator *dec
return error_mark_node;
}
}
+ else if (sfk == sfk_constructor && friendp)
+ {
+ error ("expected qualified name in friend declaration "
+ "for constructor %qD",
+ id_declarator->u.id.unqualified_name);
+ return error_mark_node;
+ }
/* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
function_context = (ctype != NULL_TREE) ?
--- gcc/testsuite/g++.dg/parse/friend7.C.jj 2007-12-17 15:05:39.000000000 +0100
+++ gcc/testsuite/g++.dg/parse/friend7.C 2007-12-17 15:04:38.000000000 +0100
@@ -0,0 +1,37 @@
+// PR c++/34488
+// { dg-do compile }
+
+struct A
+{
+ A ();
+ ~A ();
+ A (const A &);
+};
+
+struct B
+{
+ friend A::A ();
+ friend A::~A ();
+ friend A::A (const A &);
+};
+
+struct C
+{
+ friend int C (); // { dg-error "return type|in friend decl" }
+ friend int ~C (); // { dg-error "return type|in friend decl" }
+ friend int C (const C &); // { dg-error "return type|in friend decl" }
+};
+
+struct D
+{
+ friend int D () {} // { dg-error "return type|in friend decl" }
+ friend int ~D () {} // { dg-error "return type|in friend decl" }
+ friend int D (const D &) {} // { dg-error "return type|in friend decl" }
+};
+
+struct E
+{
+ friend A::A () {} // { dg-error "cannot define member" }
+ friend A::~A () {} // { dg-error "cannot define member" }
+ friend A::A (const A &) {} // { dg-error "cannot define member" }
+};
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Avoid ICE on invalid struct A { friend int A () {} } (PR c++/34488)
2007-12-17 15:11 [C++ PATCH] Avoid ICE on invalid struct A { friend int A () {} } (PR c++/34488) Jakub Jelinek
@ 2007-12-17 16:42 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2007-12-17 16:42 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Mark Mitchell, gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-12-17 16:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-17 15:11 [C++ PATCH] Avoid ICE on invalid struct A { friend int A () {} } (PR c++/34488) Jakub Jelinek
2007-12-17 16:42 ` 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).