User account creation filtered due to spam.

Bug 18512 - [3.4 Regression] ICE on invalid usage of template base class
Summary: [3.4 Regression] ICE on invalid usage of template base class
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.2
: P2 normal
Target Milestone: 3.4.5
Assignee: Volker Reichelt
Keywords: ice-on-invalid-code, monitored
: 21157 (view as bug list)
Depends on:
Reported: 2004-11-16 02:13 UTC by Jan Ringos
Modified: 2005-09-01 15:24 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-26 18:42:06


Note You need to log in before you can comment on or make changes to this bug.
Description Jan Ringos 2004-11-16 02:13:14 UTC

I was just wondering around code and following code resulted in ICE (MinGW 
3.4.2). I don't think that this is some kind of terrible bug as the code is 
obviously wrong (or isn't it?). Maybe you'll want to know about it, at least 
the compiler want me to report bug :) Maybe someone already reported 
it ...unfortunately have no time to browse buglists... :(

The error message is:

g++.exe -c main.cpp -o main.o -I"C:/Code/Dev-Cpp/include"  




-I"C:/Code/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -save-temps -Wall  
main.cpp: In member function `virtual const int iii::get_callback() const':
main.cpp:13: internal compiler error: in lookup_member, at cp/search.c:1288
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:> for instructions.make.exe: *** 
[main.o] Error 1

Yes I know it says to contact MinGW but I think the ICEs are better to submit 
to GCC directly, aren't they?

The codes are:

--- main.cpp ---
#include <stdlib.h>
#include <stdio.h>
#include "cProperty.tcc"

class iii : public property<int> {
        iii() { };
        iii(int i) : property<int>(i) { };
        const int get_callback() const {
            printf("my getcb\n");
            return this->property<int>; // this causes the ICE

int main(int argc, char *argv[]) {
    iii *i = new iii;
    printf("::: %d\n", (int)*i );
    *i = 1;
    printf("::: %d\n", (int)*i );
    delete i;
    return 0;

--- EOF ---
--- cProperty.tcc ---

template <typename T> class property {
        T _p;
        virtual const T get_callback() const { printf("getcb\n"); return _p; };
        virtual const T set_callback(const T& p) const { printf("setcb\n"); 

p; };
        property() { };
        property(const T &p) { this->_p = set_callback(p); };
        virtual ~property() { };
        virtual operator T() const { return get_callback(); };
        virtual const T& operator=(const T &p) { return this->_p = set_callback



--- EOF ---

Well, there is a lot of code that could be stripped but I hope you can browse 

through it.
Have a good time.
Comment 1 Andrew Pinski 2004-11-16 02:21:15 UTC

: Search converges between 2003-07-08-trunk (#288) and 2003-07-09-trunk (#289).

reduced testcase:

template <typename T> struct property {
struct iii : public property<int> {
        const int get_callback() const {
            return this->property<int>;
Comment 2 Volker Reichelt 2004-11-16 02:35:04 UTC
More compact testcase:

template<int> struct A {};

struct B : A<0>
    void foo() { this->A<0>; }

This is really invalid code.
Comment 3 CVS Commits 2004-11-29 20:10:48 UTC
Subject: Bug 18512

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2004-11-29 20:10:18

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog cp-tree.def cp-tree.h decl.c error.c 
	                 friend.c parser.c pt.c 
	gcc/testsuite/g++.old-deja/g++.brendan: crash16.C 
	gcc/testsuite/g++.old-deja/ ctors5.C 
	gcc/testsuite/g++.old-deja/g++.other: crash25.C 
Added files:
	gcc/testsuite/g++.dg/template: error16.C crash29.C 

Log message:
	PR c++/18368
	* parser.c (cp_parser_check_for_definition_in_return_type): Take
	the defined type as a parameter, and inform the user about the
	possibility of a missing semicolon.
	(cp_parser_explicit_instantiation): Adjust call to
	(cp_parser_init_declarator): Likewise.
	(cp_parser_member_declaration): Likewise.
	PR c++/18674
	* cp-tree.def (TYPENAME_TYPE): Remove discussion of implicit
	typename from comments.
	* cp-tree.h (TYPENAME_IS_ENUM_P): New macro.
	(make_typename_type): Change prototype.
	* decl.c (struct_typename_info): New type.
	(typename_compare): Expect the second argument to be a
	typename_info, not a tree.
	(build_typename_type): Add tag_type parameter.  Do not create a
	new type until necessary.
	(make_typename_type): Add tag_type parameter.
	* error.c (TYPENAME_TYPE): Print tags other than "typename" if
	* friend.c (make_friend_class): Adjust call to make_typename_type.
	* parser.c (cp_parser_make_typename_type): Likewise.
	(cp_parser_primary_expression): Adjust call to
	(cp_parser_unqualified_id): Adjust calls to cp_parser_class_name.
	(cp_parser_class_or_namespace_name): Likewise.
	(cp_parser_postfix_expression): Adjust calls to
	(cp_parser_mem_initializer_id): Adjust calls to
	(cp_parser_type_parameter): Adjust calls to cp_parser_lookup_name.
	(cp_parser_template_name): Likewise.
	(cp_parser_template_argument): Likewise.
	(cp_parser_type_name): Adjust call to cp_parser_class_name.
	(cp_parser_elaborated_type_specifier): Adjust calls to
	make_typename_type and cp_parser_lookup_name.
	(cp_parser_namespace_name): Likewise.
	(cp_parser_class_name): Replace type_p parameter with tag_type.
	Adjust calls to make_typename_type and cp_parser_lookup_name.
	(cp_parser_class_head): Adjust calls to cp_parser_class_name.
	(cp_parser_base_specifier): Likewise.
	(cp_parser_lookup_name): Replace is_type parameter with tag_type.
	Adjust calls to make_typename_type and lookup_qualified_name.
	(cp_parser_lookup_name_simple): Adjust call to
	(cp_parser_constructor_declarator_p): Adjust call to
	* pt.c (convert_template_argument): Adjust all to
	(tsubst_decl): Do not pre-substitute the type of the declaration.
	(tsubst): Hand off declarations more quickly.  Adjust call to
	PR c++/18512
	* parser.c (cp_parser_postfix_dot_deref_expression): Robustify.
	PR c++/18674
	* g++.old-deja/g++.brendan/crash16.C: Adjust error messages.
	* g++.old-deja/ Likewise.
	* g++.old-deja/g++.other/crash25.C: Likewise.
	PR c++/18674
	* g++.dg/template/error16.C: New test.
	PR c++/18512
	* g++.dg/template/crash29.C: New test.


Comment 4 Mark Mitchell 2004-11-29 20:25:25 UTC
Fixed in 4.0.
Comment 5 Andrew Pinski 2005-04-22 04:11:20 UTC
*** Bug 21157 has been marked as a duplicate of this bug. ***
Comment 6 Volker Reichelt 2005-09-01 14:58:22 UTC
Taking care of the backport to the 3.4 branch.
Comment 7 CVS Commits 2005-09-01 15:23:33 UTC
Subject: Bug 18512

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	2005-09-01 15:23:21

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

Log message:
	2004-11-27  Mark Mitchell  <>
	PR c++/18512
	* parser.c (cp_parser_postfix_expression): Robustify.
	* g++.dg/template/crash29.C: New test.


Comment 8 Volker Reichelt 2005-09-01 15:24:22 UTC
Fixed also on the 3.4 branch.