Bug 84348 - [7 Regression] ICE with invalid friend declaration
Summary: [7 Regression] ICE with invalid friend declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P4 normal
Target Milestone: 8.0
Assignee: Paolo Carlini
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-02-12 20:20 UTC by Volker Reichelt
Modified: 2019-11-14 11:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.4.0, 6.4.0, 8.0
Known to fail: 7.3.0, 7.5.0
Last reconfirmed: 2018-02-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2018-02-12 20:20:01 UTC
The followong invalid code snippet triggers an ICE since GCC 7.1.0:

========================================
template<typename> struct A
{
  friend auto foo;
};
========================================

bug.cc:3:15: error: 'foo' is neither function nor member function; cannot be declared friend
   friend auto foo;
               ^~~
bug.cc:3:15: internal compiler error: in cp_finish_decl, at cp/decl.c:6806
0x6000c1 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
	../../gcc/gcc/cp/decl.c:6806
0x8b0037 grokfield(cp_declarator const*, cp_decl_specifier_seq*, tree_node*, bool, tree_node*, tree_node*)
	../../gcc/gcc/cp/decl2.c:1002
0x9260ee cp_parser_member_declaration
	../../gcc/gcc/cp/parser.c:23871
0x92707a cp_parser_member_specification_opt
	../../gcc/gcc/cp/parser.c:23345
0x92707a cp_parser_class_specifier_1
	../../gcc/gcc/cp/parser.c:22487
0x9290d9 cp_parser_class_specifier
	../../gcc/gcc/cp/parser.c:22739
0x9290d9 cp_parser_type_specifier
	../../gcc/gcc/cp/parser.c:16745
0x936266 cp_parser_decl_specifier_seq
	../../gcc/gcc/cp/parser.c:13606
0x93a9a5 cp_parser_single_declaration
	../../gcc/gcc/cp/parser.c:27051
0x93ad2c cp_parser_template_declaration_after_parameters
	../../gcc/gcc/cp/parser.c:26743
0x93b5ec cp_parser_explicit_template_declaration
	../../gcc/gcc/cp/parser.c:26980
0x93b5ec cp_parser_template_declaration_after_export
	../../gcc/gcc/cp/parser.c:26999
0x940959 cp_parser_declaration
	../../gcc/gcc/cp/parser.c:12710
0x940c41 cp_parser_declaration_seq_opt
	../../gcc/gcc/cp/parser.c:12637
0x940f34 cp_parser_translation_unit
	../../gcc/gcc/cp/parser.c:4559
0x940f34 c_parse_file()
	../../gcc/gcc/cp/parser.c:38857
0xa3f566 c_common_parse_file()
	../../gcc/gcc/c-family/c-opts.c:1132
Please submit a full bug report, [etc.]
Comment 1 Martin Sebor 2018-02-13 00:37:05 UTC
Confirmed.  The ICE originated with 240756 (GCC 7.0.0):

r240756 | jason | 2016-10-04 16:42:58 -0400 (Tue, 04 Oct 2016) | 23 lines

Implement P0091R2, Template argument deduction for class templates.
Comment 2 Paolo Carlini 2018-02-16 15:56:09 UTC
Mine.
Comment 3 paolo@gcc.gnu.org 2018-02-19 08:50:02 UTC
Author: paolo
Date: Mon Feb 19 08:49:30 2018
New Revision: 257802

URL: https://gcc.gnu.org/viewcvs?rev=257802&root=gcc&view=rev
Log:
/cp
2018-02-19  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84348
	* decl.c (grokdeclarator): Early return error_mark_node upon
	ill-formed friend declaration.

/testsuite
2018-02-19  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84348
	* g++.dg/cpp0x/auto50.C: New.
	* g++.dg/parse/friend12.C: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/auto50.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/parse/friend12.C
Comment 4 Paolo Carlini 2018-02-19 09:17:58 UTC
Fixed in trunk.
Comment 5 Richard Biener 2019-11-14 11:06:46 UTC
Fixed in GCC 8.