This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix 21165
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 31 May 2005 19:01:03 +0100
- Subject: [C++ PATCH] Fix 21165
This patch fixes 21165, a problem caused by our propensity to early fold stuff.
In a template the initializer of a constant variable might not be of the
expected type.
built & tested on i686-pc-linux-gnu, installed HEAD and 4.0 branch
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2005-05-31 Nathan Sidwell <nathan@codesourcery.com>
PR c++/21165
* init.c (integral_constant_value): Check the type of the
initializer, not the decl.
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.419
diff -c -3 -p -r1.419 init.c
*** cp/init.c 23 Apr 2005 21:28:53 -0000 1.419
--- cp/init.c 31 May 2005 17:18:14 -0000
*************** integral_constant_value (tree decl)
*** 1573,1579 ****
&& DECL_INITIAL (decl)
&& DECL_INITIAL (decl) != error_mark_node
&& TREE_TYPE (DECL_INITIAL (decl))
! && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
decl = DECL_INITIAL (decl);
return decl;
}
--- 1573,1579 ----
&& DECL_INITIAL (decl)
&& DECL_INITIAL (decl) != error_mark_node
&& TREE_TYPE (DECL_INITIAL (decl))
! && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (DECL_INITIAL (decl))))
decl = DECL_INITIAL (decl);
return decl;
}
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 31 May 2005 <nathan@codesourcery.com>
// PR 21165. ICE on valid
// Origin:Volker Reichelt reichelt@gcc.gnu.org
template<typename T> bool foo()
{
const int i = T();
return i > 0;
}