Bug 28346

Summary: [4.0 regression] ICE creating pointer-to-reference-member
Product: gcc Reporter: Volker Reichelt <reichelt>
Component: c++Assignee: Mark Mitchell <mark>
Status: RESOLVED FIXED    
Severity: normal CC: fang, gcc-bugs, nathan
Priority: P2 Keywords: ice-on-invalid-code, monitored
Version: 4.2.0   
Target Milestone: 4.1.2   
Host: Target:
Build: Known to work: 4.1.2 4.2.0 4.3.0
Known to fail: 4.1.1 Last reconfirmed: 2006-08-14 19:04:06

Description Volker Reichelt 2006-07-11 16:11:44 UTC
The following invalid code snippet triggers an ICE since GCC 4.0.0:

=========================================
template<int> struct A
{
    int& i;
    A();
    ~A() { &A::i; }
};

A<0> a;
=========================================

bug.cc: In destructor 'A<<anonymous> >::~A() [with int <anonymous> = 0]':
bug.cc:9:   instantiated from here
bug.cc:6: internal compiler error: in gimplify_expr, at gimplify.c:5763
Please submit a full bug report, [etc.]

Before we got the error message:

bug.cc: In destructor `void A<<anonymous> >::A() [with int <anonymous> = 0]':
bug.cc:9:   instantiated from here
bug.cc:6: cannot create pointer to reference member `A<0>::i'
Comment 1 Janis Johnson 2006-08-12 21:37:54 UTC
A regression hunt on powerpc-linux identified the following patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=93055

    r93055 | nathan | 2005-01-07 17:09:15 +0000 (Fri, 07 Jan 2005)
Comment 2 Volker Reichelt 2006-08-14 19:04:06 UTC
Confirmed by Janis.
Comment 3 Mark Mitchell 2006-08-20 23:53:19 UTC
Subject: Bug 28346

Author: mmitchel
Date: Sun Aug 20 23:53:10 2006
New Revision: 116276

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116276
Log:
	PR c++/28341
	* tree.c (cast_valid_in_integral_constant_expression_p): New
	function.
	* cp-tree.h (tsubst_copy_and_build): Adjust prototype.
	* pt.c (tsubst_expr): Add integral_constant_expression_p
	parameter.
	(fold_non_dependent_expr): Adjust callers of
	tsubst_{expr,copy_and_build}.
	(tsubst_friend_function): Likewise.
	(tsubst_template_arg): Likewise.
	(tsubst_default_argument): Likewise.
	(tsubst_decl): Likewise.
	(tsubst): Likewise.
	(tsubst_omp_clasuses): Likewise.
	(regenerate_decl_fromp_template): Likewise.
	(instantiate_decl): Likewise.
	(tsubst_initializer_list): Likewise.
	(tsubst_enum): Likewise.
	(tsubst_expr): Use RECUR throughout.
	(tsubst_copy_and_build): Change definition of RECUR.  Do not allow
	invalid casts in integral constant expressions.
	* parser.c (cp_parser_postfix_expression): Use
	cast_valid_in_integral_constant_expression_p.
	(cp_parser_cast_expression): Likewise.
	(cp_parser_functional_cast): Likewise.

	PR c++/28346
	* pt.c (tsubst_qualified_id): Do not strip references from
	OFFSET_REFs. 

2006-08-20  Mark Mitchell  <mark@codesourcery.com>

	PR c++/28341
	* g++.dg/template/ref3.C: New test.
	* g++.dg/template/nontype13.C: New test.

	PR c++/28346
	* g++.dg/template/ptrmem17.C: New test.


2006-08-20  Mark Mitchell  <mark@codesourcery.com>

	* objcp-lang.c (objcp_tsubst_copy_and_build): Adjust call to
	tsubst_copy_and_build.

Added:
    trunk/gcc/testsuite/g++.dg/template/ptrmem17.C
    trunk/gcc/testsuite/g++.dg/template/ref3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/objcp/ChangeLog
    trunk/gcc/objcp/objcp-lang.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/template/nontype13.C

Comment 4 Mark Mitchell 2006-08-20 23:59:53 UTC
Fixed in 4.2.0.
Comment 5 Mark Mitchell 2006-08-21 00:42:20 UTC
Fixed in 4.1.2.
Comment 6 Mark Mitchell 2006-08-21 00:42:25 UTC
Subject: Bug 28346

Author: mmitchel
Date: Mon Aug 21 00:41:50 2006
New Revision: 116283

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116283
Log:
	PR c++/28346
	* pt.c (tsubst_qualified_id): Do not strip references from
	OFFSET_REFs. 
	PR c++/28346
	* g++.dg/template/ptrmem17.C: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/ptrmem17.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/pt.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 7 Volker Reichelt 2006-10-05 23:28:51 UTC
Because of Jason's patch for PR 28346 the code is now wrongly accepted
on the 4.0 branch. With a slightly different testcase I can still
trigger the ICE, though:

==========================================
bool b;

template<int> struct A
{
    int& i;
    A();
    ~A() { b = (&A::i == &A::i); }
};

A<0> a;
==========================================
Comment 8 Volker Reichelt 2006-10-05 23:29:31 UTC
I meant Jason's patch for PR 26696, of course.
Comment 9 Gabriel Dos Reis 2007-02-03 18:02:12 UTC
Fixed in GCC-4.1.2.