From 50dbbe535766405327cdf4cf6712a633a87966e0 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 19 Feb 2018 08:49:30 +0000 Subject: [PATCH] re PR c++/84348 (ICE with invalid friend declaration) /cp 2018-02-19 Paolo Carlini PR c++/84348 * decl.c (grokdeclarator): Early return error_mark_node upon ill-formed friend declaration. /testsuite 2018-02-19 Paolo Carlini PR c++/84348 * g++.dg/cpp0x/auto50.C: New. * g++.dg/parse/friend12.C: Adjust. From-SVN: r257802 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 2 +- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/auto50.C | 7 +++++++ gcc/testsuite/g++.dg/parse/friend12.C | 1 - 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto50.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 728c501ad55..7ebd5ab0384 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-19 Paolo Carlini + + PR c++/84348 + * decl.c (grokdeclarator): Early return error_mark_node upon + ill-formed friend declaration. + 2018-02-16 Marek Polacek Jakub Jelinek diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 15f7f122462..f91f311a117 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12141,7 +12141,7 @@ grokdeclarator (const cp_declarator *declarator, { error ("%qE is neither function nor member function; " "cannot be declared friend", unqualified_id); - friendp = 0; + return error_mark_node; } decl = NULL_TREE; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 50643570f3d..c91b26149f4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-02-19 Paolo Carlini + + PR c++/84348 + * g++.dg/cpp0x/auto50.C: New. + * g++.dg/parse/friend12.C: Adjust. + 2018-02-18 Jerry DeLisle PR libgfortran/84389 diff --git a/gcc/testsuite/g++.dg/cpp0x/auto50.C b/gcc/testsuite/g++.dg/cpp0x/auto50.C new file mode 100644 index 00000000000..814892d2afa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto50.C @@ -0,0 +1,7 @@ +// PR c++/84348 +// { dg-do compile { target c++11 } } + +template struct A +{ + friend auto foo; // { dg-error "cannot be declared friend" } +}; diff --git a/gcc/testsuite/g++.dg/parse/friend12.C b/gcc/testsuite/g++.dg/parse/friend12.C index 84d6e25e766..d4e0ceea9ac 100644 --- a/gcc/testsuite/g++.dg/parse/friend12.C +++ b/gcc/testsuite/g++.dg/parse/friend12.C @@ -3,5 +3,4 @@ struct A { friend int i = 0; // { dg-error "cannot be declared friend" } -// { dg-error "non-static data member" "" { target { ! c++11 } } .-1 } }; -- 2.30.2