diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e4c22446150..91d8cea79c8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-12-18 Jakub Jelinek + + PR c++/34488 + * decl.c (grokdeclarator): Reject friend sfk_constructor + FUNCTION_TYPE. + 2007-12-17 Jakub Jelinek PR c/34506 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6cbf1f142c3..f968e88c0c5 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8818,6 +8818,13 @@ grokdeclarator (const cp_declarator *declarator, 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) ? diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d42c3345884..e75f2aa0aad 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2007-12-18 Jakub Jelinek + PR c++/34488 + * g++.dg/parse/friend7.C: New test. + PR rtl-optimization/34490 * gcc.c-torture/execute/20071216-1.c: New test. diff --git a/gcc/testsuite/g++.dg/parse/friend7.C b/gcc/testsuite/g++.dg/parse/friend7.C new file mode 100644 index 00000000000..668fd35d37c --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/friend7.C @@ -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" } +};