Bug 22172 - [3.4 Regression] Internal compiler error, seg fault.
Summary: [3.4 Regression] Internal compiler error, seg fault.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 3.4.5
Assignee: Volker Reichelt
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-invalid-code, ice-on-valid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2005-06-24 12:41 UTC by Tom M.
Modified: 2005-11-15 19:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3 3.3.6 4.1.0
Known to fail: 3.4.0 3.4.4 4.0.0
Last reconfirmed: 2005-09-04 18:20:32


Attachments
The ii file from the compiler output where I received the seg fault. (120.17 KB, text/plain)
2005-06-24 12:43 UTC, Tom M.
Details
We should give the user an error message (628 bytes, patch)
2005-09-24 20:44 UTC, James A. Morrison
Details | Diff
Treat non-types as non-dependent (488 bytes, patch)
2005-09-28 04:25 UTC, James A. Morrison
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom M. 2005-06-24 12:41:48 UTC
This internal compiler error is being generated when I add the 
keyword 'typename' to a line of code that 

before that was giving me an error that:  SAX/wrappers/saxlibxml2.h:310: error: 
expected primary-expression 

before '*' token. 

In the saxlibxml2.ii file, it is at line 35577. 


Specs from /usr/local/lib/gc/mips-sgi-irix6.5/3.4.4/specs
Configured with ./configure
Thread model: single
gcc v3.4.4

Command line: 
g++ -c -I../../Include/SAX ../../Include/SAX/wrappers/saxlibxml2.cpp -
o ../../Include/SAX/wrappers/saxlibxml2.o

Compiler output:

In file included 
from ../../Include/SAX/wrappers/saxlibxml2.cpp:7: ../../Include/SAX/wrappers/sax
libxml2.h: In 

member function 'virtual std::auto_ptr<typename 
SAX::basic_XMLreader<string_type>::PropertyBase> 

SAX::libxml2_wrapper<string_type, string_adapter_type>::doGetProperty(const 
string_type&)':
.../SAX/wrappers/saxlibxml2.:311: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
gmake: *** [../../Include/SAX/wrappers/saxlibxml2.o] Error 1
Comment 1 Tom M. 2005-06-24 12:43:58 UTC
Created attachment 9143 [details]
The ii file from the compiler output where I received the seg fault.

Line 35577 in this file contains the 'typename' that I added to make this
compiler have an internal error. Without this keyword, I get a compile error.
So, it seems to be required...but I can't build my source.
Comment 2 Andrew Pinski 2005-06-24 13:30:48 UTC
Confirmed, here is a reduced testcase:
template<class a>
struct cla
{
  template<typename b>
  struct clb {};
};
namespace nasa { template<class a> struct clc {}; }
template<class a>
void doGetProperty(void)
{
    cla<a>::clb<typename nasa::clc<a> *> *prop;
}
--- ICE ---
pr22172.cc:12: internal compiler error: tree check: expected class 'type', have 'declaration' 
(namespace_decl) in dependent_type_p, at cp/pt.c:12027
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 3 Volker Reichelt 2005-06-24 15:30:44 UTC
Your line should read:

  typename SAX::basic_XMLReader<stringT>::template
Property<SAX::basic_DeclHandler<stringT> *>* prop;

If one fixes all four occurances in your file, the code compiles fine.


With your version

    SAX::basic_XMLReader<stringT>::Property<typename
SAX::basic_DeclHandler<stringT> *>* prop;

"SAX::basic_XMLReader<stringT>::Property" is not a type, and therefore "<"
is the operator "less_than" which is followed by a type (followed by some
more stuff, but the compiler already crashed).


An even shorter testcase is the following:

===========================================
namespace N { template<int> struct A {}; }

template<typename> void foo()
{
    +typename N::A<0>;
}
===========================================
Comment 4 Andrew Pinski 2005-07-22 21:13:23 UTC
Moving to 4.0.2 pre Mark.
Comment 5 James A. Morrison 2005-09-24 20:44:33 UTC
Created attachment 9800 [details]
We should give the user an error message

 Anyone have a better error message?
Comment 6 Andrew Pinski 2005-09-24 20:59:56 UTC
Only the following:
if (TREE_CODE_CLASS (TREE_CODE (scope)) != tcc_type)
Should be:
if (!TYPE_P (scope))

-- Pinski
Comment 7 Volker Reichelt 2005-09-26 08:09:57 UTC
I don't think that this is a proper fix, since the following IMHO valid
code snippet is rejected:

====================================================================
namespace N { template<int> struct A { operator int() const; }; }

template<typename> void foo()
{
    +typename N::A<0>();
}
====================================================================
Comment 8 James A. Morrison 2005-09-26 17:31:50 UTC
 So this is an ice-on-valid and an ice-on-invalid bug then?
Comment 9 Wolfgang Bangerth 2005-09-26 19:00:58 UTC
The testcase in comment #3 shows an ice-on-invalid. The testcase in 
comment #7 is valid, and ices anyway. 
 
W. 
Comment 10 James A. Morrison 2005-09-28 04:25:39 UTC
Created attachment 9825 [details]
Treat non-types as non-dependent

This fixes the ice on all three testcases here.  The first two now give errors
and the third testcase compiles without error.
Comment 11 Mark Mitchell 2005-10-01 11:07:40 UTC
This path is OK, without the spurious addition of the blank line.
Comment 12 GCC Commits 2005-10-08 18:11:06 UTC
Subject: Bug 22172

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	phython@gcc.gnu.org	2005-10-08 18:11:02

Modified files:
	gcc/cp         : ChangeLog parser.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/parse: crash30.C 

Log message:
	2005-10-08  James A. Morrison  <phython@gcc.gnu.org>
	
	PR c++/22172
	* parser.c (cp_parser_postfix_expression) <RID_TYPENAME>: Treat nontype
	scopes as nondependent.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4914&r2=1.4915
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.360&r2=1.361
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6151&r2=1.6152
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/crash30.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 13 James A. Morrison 2005-10-08 18:13:07 UTC
fixed in the previous patch.
Comment 14 Volker Reichelt 2005-11-03 11:25:49 UTC
Now also fixed on the 3.4 branch due to Mark's patch for PR 19253:
http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00141.html
I'd really like to get that one backported to the 3.4 branch
Comment 15 Volker Reichelt 2005-11-03 11:26:26 UTC
I meant the 4.0 branch of course.
Comment 16 Volker Reichelt 2005-11-09 17:12:20 UTC
Backport for the 3.4 branch.
Comment 17 Volker Reichelt 2005-11-15 19:14:25 UTC
Subject: Bug 22172

Author: reichelt
Date: Tue Nov 15 19:14:21 2005
New Revision: 107037

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107037
Log:
	PR c++/19253
	PR c++/22172
	Backport from mainline:
	2005-11-02  Mark Mitchell  <mark@codesourcery.com>

	* parser.c (cp_parser_postfix_expression): Use
	cp_parser_elaborated_type_specifier to handle typename-types in
	functional casts.
	(cp_parser_enclosed_argument_list): Skip ahead to the end of the
	template argument list if the closing ">" is not found.


	Backport from mainline:
	2005-11-02  Mark Mitchell  <mark@codesourcery.com>

	PR c++/19253
	* g++.dg/parse/typename10.C: New test.

	Backport from mainline:
	2005-10-08  James A. Morrison  <phython@gcc.gnu.org>

	PR c++/22172
	* g++.dg/parse/crash30.C: New test.


Added:
    branches/gcc-3_4-branch/gcc/testsuite/g++.dg/parse/crash30.C
    branches/gcc-3_4-branch/gcc/testsuite/g++.dg/parse/typename10.C
Modified:
    branches/gcc-3_4-branch/gcc/cp/ChangeLog
    branches/gcc-3_4-branch/gcc/cp/parser.c
    branches/gcc-3_4-branch/gcc/testsuite/ChangeLog

Comment 18 Volker Reichelt 2005-11-15 19:18:35 UTC
Now also fixed on the 3.4 branch.