Bug 18161 - [4.0 regression] typeof(1==1) is now int instead of bool in template default arguments
Summary: [4.0 regression] typeof(1==1) is now int instead of bool in template default ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Mark Mitchell
URL:
Keywords: monitored, rejects-valid, wrong-code
Depends on:
Blocks:
 
Reported: 2004-10-26 13:30 UTC by Wolfgang Bangerth
Modified: 2004-10-27 04:23 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95 3.2 3.3 3.4.3
Known to fail: 4.0.0
Last reconfirmed: 2004-10-26 13:34:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bangerth 2004-10-26 13:30:22 UTC
For this code 
----------------- 
template <typename = typeof(1==1)> struct X { X(){} }; 
template struct X<>; 
----------------- 
I would expect an instantiation of X<bool>, and indeed got it up to 
3.4. However, since 4.0 we get X<int>: 
 
g/x> /home/bangerth/bin/gcc-3.4*/bin/c++ -c x.cc ; nm -C x.o 
00000000 W X<bool>::X() 
00000000 W X<bool>::X() 
g/x> /home/bangerth/bin/gcc-4*/bin/c++ -c x.cc ; nm -C x.o 
00000000 W X<int>::X() 
00000000 W X<int>::X() 
 
 
This is somehow odd, since for a related piece of code 
------------------- 
template <typename> struct X {}; 
void foo(X<typeof(1==1)>) {} 
------------------- 
there is no regression: 
 
g/x> /home/bangerth/bin/gcc-3.4*/bin/c++ -c y.cc ; nm -C y.o 
00000000 T foo(X<bool>) 
g/x> /home/bangerth/bin/gcc-4*/bin/c++ -c y.cc ; nm -C y.o 
00000000 T foo(X<bool>) 
 
W.
Comment 1 Andrew Pinski 2004-10-26 13:34:25 UTC
Here is a testcase which we can see the problem with rejecting the code (which is very useful for the 
regression hunter :) ):
template <class T> struct Y;
template <>struct Y<bool>{};

template <typename T = typeof(1==1)> struct X { Y<T> a; }; 
template struct X<>; 

: Search converges between 2004-09-27-161002-trunk (#564) and 2004-09-28-014001-trunk 
(#565).
Comment 2 Andrew Pinski 2004-10-26 13:36:00 UTC
Almost certain that this was caused by:
2004-09-27  Mark Mitchell  <mark@codesourcery.com>
        
        PR c++/17642
        * cp-tree.h (fold_if_not_in_template): New function.
        * call.c (build_conditional_expr): Use fold_if_not_in_template.
        (build_cxx_call): Likewise.
        * cvt.c (convert_to_complex): Likewise.
        (ocp_convert): Likewise.
        (convert): Likewise.
        (convert_force): Likewise.
        * decl.c (compute_array_index_type): Clear
        processing_template_decl while folding array bounds.
        * pt.c (convert_nontype_argument): Clear
        processing_template_decl while processing non-type argument
        initialization.
        * tree.c (fold_if_not_in_template): New function.
        * typeck.c (build_class_member_access_expr): Use
        fold_if_not_in_template.
        (build_array_ref): Likewise.
        (build_binary_op): Likewise.  Do not try to optimize computations
        when processing templates.
        (cp_pointer_int_sum): Use fold_if_not_in_template.
        (pointer_diff): Likewise.
        (build_unary_op): Likewise.
        (build_reinterpret_cast): Likewise.
        (get_delta_difference): Likewise.
        (expand_ptrmemfunc_cst): Likewise.
        (dubious_conversion_warnings): Likewise.
Comment 3 GCC Commits 2004-10-27 02:23:22 UTC
Subject: Bug 18161

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-10-27 02:23:16

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog decl.c name-lookup.c parser.c pt.c 
	                 search.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/lookup: ns2.C 
	gcc/testsuite/g++.dg/template: enum4.C expr1.C 

Log message:
	PR c++/18093
	* search.c (current_scope): Return the innermost non-block scope,
	not the innermost non-block, non-namespace scope.
	(at_namespace_scope_p): Adjust accordingly.
	(dfs_accessible_post): Do not pass namespaces to is_friend.
	(dfs_walk_once_accessible_r): Likewise.
	* decl.c (grokvardecl): Adjust call to current_scope.
	(build_enumerator): Likewise.
	* parser.c (cp_parser_using_declaration): Likewise.
	(cp_parser_direct_declarator): Use at_namespace_scope_p instead of
	current_scope.
	(cp_parser_class_head): Adjust call to current_scope.
	* name-lookup.c (do_namespace_alias): Set the DECL_CONTEXT for the
	alias.
	
	PR c++/18020
	* pt.c (tusbst_copy_and_build): Resolve enumeration constants to
	their underlying values.
	
	PR c++/18161
	* typeck.c (build_binary_op): Honor build_type, even when in a
	template.
	
	PR c++/18093
	* g++.dg/lookup/ns2.C: New test.
	
	PR c++/18020
	* g++.dg/template/enum4.C: New test.
	
	PR c++/18161
	* g++.dg/template/expr1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4501&r2=1.4502
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4454&r2=1.4455
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1318&r2=1.1319
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.87&r2=1.88
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.270&r2=1.271
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.937&r2=1.938
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.335&r2=1.336
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.588&r2=1.589
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ns2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/expr1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Mark Mitchell 2004-10-27 04:23:46 UTC
Fixed in GCC 4.0.