Bug 84375 - [8 Regression] ICE with friend in local class
Summary: [8 Regression] ICE with friend in local class
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P4 normal
Target Milestone: 8.0
Assignee: Nathan Sidwell
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks: c++-lookup, c++-name-lookup
  Show dependency treegraph
 
Reported: 2018-02-13 20:59 UTC by Volker Reichelt
Modified: 2018-02-16 14:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
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-13 20:59:26 UTC
The following invalid testcase triggers an ICE on trunk:

===========================
void foo()
{
  struct A
  {
    friend void A();
  };
}
===========================

bug.cc: In function 'void foo()':
bug.cc:5:19: error: friend declaration 'void A()' in local class without prior local declaration
     friend void A();
                   ^
bug.cc:6:4: internal compiler error: in pop_local_binding, at cp/name-lookup.c:2062
   };
    ^
0x61f401 pop_local_binding(tree_node*, tree_node*)
	../../gcc/gcc/cp/name-lookup.c:2062
0x8962ad poplevel(int, int, int)
	../../gcc/gcc/cp/decl.c:776
0x99e5c3 do_poplevel(tree_node*)
	../../gcc/gcc/cp/semantics.c:451
0x9a0149 finish_compound_stmt(tree_node*)
	../../gcc/gcc/cp/semantics.c:1450
0x91cd0f cp_parser_compound_statement
	../../gcc/gcc/cp/parser.c:11211
0x933460 cp_parser_function_body
	../../gcc/gcc/cp/parser.c:21747
0x933460 cp_parser_ctor_initializer_opt_and_function_body
	../../gcc/gcc/cp/parser.c:21784
0x933d10 cp_parser_function_definition_after_declarator
	../../gcc/gcc/cp/parser.c:26685
0x934a27 cp_parser_function_definition_from_specifiers_and_declarator
	../../gcc/gcc/cp/parser.c:26601
0x934a27 cp_parser_init_declarator
	../../gcc/gcc/cp/parser.c:19473
0x93bac8 cp_parser_simple_declaration
	../../gcc/gcc/cp/parser.c:13038
0x93c8d8 cp_parser_block_declaration
	../../gcc/gcc/cp/parser.c:12863
0x940832 cp_parser_declaration
	../../gcc/gcc/cp/parser.c:12761
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.]

The regression was introduced between 2017-05-19 and 2017-05-25.
Nathan, this might be related to your name-lookup changes.
Would you mind having a look?
Comment 1 Nathan Sidwell 2018-02-16 14:31:26 UTC
Author: nathan
Date: Fri Feb 16 14:30:55 2018
New Revision: 257739

URL: https://gcc.gnu.org/viewcvs?rev=257739&root=gcc&view=rev
Log:
[PR c++/84375] Fix ICE after bad friend

https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00987.html
	PR c++/84375
	* name-lookup.c (do_pushdecl): Bail out on bad local friend injection.

	* g++.dg/lookup/pr84375.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/lookup/pr84375.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Nathan Sidwell 2018-02-16 14:31:43 UTC
Fixed r257739.