Bug 71662 - [7 Regression][DR 1485] ICE on invalid C++11 code with unqualified name look up: in tsubst_copy, at cp/pt.c:14010
Summary: [7 Regression][DR 1485] ICE on invalid C++11 code with unqualified name look ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2016-06-26 05:59 UTC by Zhendong Su
Modified: 2019-11-14 09:26 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.0
Known to fail: 7.5.0
Last reconfirmed: 2016-06-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2016-06-26 05:59:24 UTC
The following C++11 code causes an ICE when compiled with the current GCC trunk on x86_64-linux-gnu in both 32-bit and 64-bit modes.  

It also affects older versions at least as early as 4.6.x. 


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20160625 (experimental) [trunk revision 237780] (GCC) 
$ 
$ g++-trunk -c -std=c++11 small.cpp
small.cpp: In instantiation of ‘A<T>::E A<T>::h() [with T = int]’:
small.cpp:8:23:   required from here
small.cpp:14:10: internal compiler error: in tsubst_copy, at cp/pt.c:14010
   return e;
          ^
0x6dfcdc tsubst_copy
        ../../gcc-source-trunk/gcc/cp/pt.c:14010
0x6e2906 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:17243
0x6d68ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15868
0x6d6f75 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15176
0x6d7e30 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:15351
0x6d4835 instantiate_decl(tree_node*, int, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:22095
0x721512 instantiate_pending_templates(int)
        ../../gcc-source-trunk/gcc/cp/pt.c:22214
0x764645 c_parse_final_cleanups()
        ../../gcc-source-trunk/gcc/cp/decl2.c:4600
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ 


----------------------------------------------------------


template < typename T > struct A
{
  enum E : T;
  E h ();
};

A < int > a;
A < int >::E b = a.h ();

template < typename T > enum A < T >::E : T { e };

template < typename T > typename A < T >::E A < T >::h ()
{
  return e; 
}
Comment 1 Jakub Jelinek 2016-06-27 08:36:34 UTC
Started with r165935.
Comment 2 Jason Merrill 2016-07-29 15:32:36 UTC
Related to http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1485 which is still in drafting.  Discussion at the October 2012 meeting suggested that an unscoped opaque enum declaration should be ill-formed.
Comment 3 Richard Biener 2016-08-03 12:04:06 UTC
GCC 4.9 branch is being closed
Comment 4 Jakub Jelinek 2017-10-10 13:26:03 UTC
GCC 5 branch is being closed
Comment 5 Paolo Carlini 2018-02-06 22:25:05 UTC
This seems fixed in trunk, we simply reject the code without ICEing. While reviewing this bug I noticed once more the nit that -Wreturn-type enabled by default means that in such cases we emit a redundant warning:

71662.C:14:10: error: ‘e’ was not declared in this scope
   return e;
          ^
71662.C: In instantiation of ‘A<T>::E A<T>::h() [with T = int]’:
71662.C:8:23:   required from here
71662.C:15:1: warning: no return statement in function returning non-void [-Wreturn-type]

but that seems an unrelated issue, really. Thus I mean to commit the testcase and remove the 8 Regression marker.
Comment 6 paolo@gcc.gnu.org 2018-02-07 09:35:42 UTC
Author: paolo
Date: Wed Feb  7 09:35:10 2018
New Revision: 257439

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

	PR c++/71662
	* g++.dg/cpp0x/scoped_enum7.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/scoped_enum7.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2018-10-26 10:09:20 UTC
GCC 6 branch is being closed
Comment 8 Richard Biener 2019-11-14 09:26:23 UTC
Fixed in GCC8.