Bug 17132 - [3.4/4.0 Regression] GCC fails to eliminate function template specialization when argument deduction fails
Summary: [3.4/4.0 Regression] GCC fails to eliminate function template specialization ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.4.3
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code, rejects-valid
Depends on:
Blocks:
 
Reported: 2004-08-21 20:52 UTC by Alex Chovanec
Modified: 2004-10-28 21:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-08-21 21:06:54


Attachments
first version of source file (275 bytes, text/plain)
2004-08-21 20:53 UTC, Alex Chovanec
Details
compiler output for first version of source file (667 bytes, text/plain)
2004-08-21 20:54 UTC, Alex Chovanec
Details
second version of source file (277 bytes, text/plain)
2004-08-21 20:55 UTC, Alex Chovanec
Details
compiler output for second version of source file (748 bytes, text/plain)
2004-08-21 20:55 UTC, Alex Chovanec
Details
third version of source file (319 bytes, text/plain)
2004-08-21 22:27 UTC, Alex Chovanec
Details
compiler output for third version of source file (760 bytes, text/plain)
2004-08-21 22:27 UTC, Alex Chovanec
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Chovanec 2004-08-21 20:52:03 UTC
When compiling test_no_amperspand.cpp, GCC generates the following error:

"error: `operator*' is not a member of type `empty'"

GCC attempts to instantiate a specialization of the function template 'test' 
which accepts a parameter of type `func_tag<Type, Type::operator*> *' with a 
default value of 0.

Since type 'empty' is a struct which does not overload `operator*', this 
specialization should not be included in the set of candidate functions for the 
call to `test' on line 19, according to the SFINAE (substitution-failure-is-not 
an-error) principle.

The C++ Standard states:

"... For each function template, if the argument deduction and checking 
succeeds, the template-arguments (deduced and/or explicit) are used to 
instantiate a single function template specialization which is added to the 
candidate functions set to be used in overload resolution. If, for a given 
function template, argument deduction fails, no such function is added to the 
set of candidate functions for that template."

Since a non-template function `test' is defined which accepts a parameter of 
type `void *', the call on 19 is satisfied. Thus, this program is correct and 
should compile.


The second file, test_amperspand.cpp, is identical to the first, except that on 
line 14, `Type::operator*' is replaced with `&Type::operator*'. (Both forms are 
correct.)

In the latter case (test_amperspand.cpp), GCC generates the following error:

"internal compiler error: Segmentation fault"


Both of these programs compile without error under Intel C++ 8.0 and Comeau 
C/C++ 4.3.0.
Comment 1 Alex Chovanec 2004-08-21 20:53:32 UTC
Created attachment 6971 [details]
first version of source file
Comment 2 Alex Chovanec 2004-08-21 20:54:22 UTC
Created attachment 6972 [details]
compiler output for first version of source file
Comment 3 Alex Chovanec 2004-08-21 20:55:05 UTC
Created attachment 6973 [details]
second version of source file
Comment 4 Alex Chovanec 2004-08-21 20:55:30 UTC
Created attachment 6974 [details]
compiler output for second version of source file
Comment 5 Andrew Pinski 2004-08-21 21:06:54 UTC
The first one now ICE in 3.4.0 so that is a regression.

Confirmed.
Comment 6 Alex Chovanec 2004-08-21 22:25:04 UTC
I am posting a third source file along with the output that GCC generates when 
I try to compile it.

Here, has_deref is instantiated with a type that defines `operator*', so 
argument deduction should succeed, and the appropriate specialization of the 
`test' function template should be called, because `Type *' is a better match 
than `void *'.

However, in this case GCC generates a different internal compiler error:

"internal compiler error: in mangle_class_name_for_template, at cp/pt.c:3848"

Comment 7 Alex Chovanec 2004-08-21 22:27:13 UTC
Created attachment 6975 [details]
third version of source file
Comment 8 Alex Chovanec 2004-08-21 22:27:59 UTC
Created attachment 6976 [details]
compiler output for third version of source file
Comment 9 Andrew Pinski 2004-08-22 17:25:38 UTC
: Search converges between 2003-07-07-trunk (#287) and 2003-07-08-trunk (#288).
Comment 10 Mark Mitchell 2004-08-29 18:11:54 UTC
Postponed until GCC 3.4.3.
Comment 11 Mark Mitchell 2004-08-29 18:14:42 UTC
Postponed until GCC 3.4.3.
Comment 12 CVS Commits 2004-10-28 20:53:09 UTC
Subject: Bug 17132

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-10-28 20:53:04

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

Log message:
	PR c++/17132
	* pt.c (instantiate_class_template): Increment
	processing_template_decl when substituting into a member class
	template.
	
	PR c++/17132
	* g++.dg/template/memclass3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4460&r2=1.4461
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.938&r2=1.939
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4513&r2=1.4514
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memclass3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 13 CVS Commits 2004-10-28 20:56:57 UTC
Subject: Bug 17132

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-10-28 20:56:55

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

Log message:
	PR c++/17132
	* pt.c (instantiate_class_template): Increment
	processing_template_decl when substituting into a member class
	template.
	
	PR c++/17132
	* g++.dg/template/memclass3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.175&r2=1.3892.2.176
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.44&r2=1.816.2.45
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.299&r2=1.3389.2.300
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memclass3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 14 Mark Mitchell 2004-10-28 21:00:59 UTC
Fixed in GCC 3.4.3.