This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH,committed] Fix PR13289 part 2 (integral or enumerationconstant check)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 29 Dec 2003 18:10:11 +0700 (ICT)
- Subject: [C++ PATCH,committed] Fix PR13289 part 2 (integral or enumerationconstant check)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This patch fixes the second problem exposed in PR13289 where
certain non-type template arguments are rejected. See the testcase
in the patch as an example. We forget to make sure that the
template argument has a non-dependent type before enforcing that
it must be an integer or enum.
Tested on i686-pc-linux-gnu. Committed to the mainline as obvious.
--Kriang
2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13289
* semantics.c (finish_id_expression): Only check if the type of
a template argument is integral or enumeration when it is not
dependent.
2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13289
* g++.dg/parse/nontype1.C: New test.
diff -cprN gcc-main-save/gcc/cp/semantics.c gcc-main-new/gcc/cp/semantics.c
*** gcc-main-save/gcc/cp/semantics.c Thu Dec 18 21:09:31 2003
--- gcc-main-new/gcc/cp/semantics.c Mon Dec 29 17:04:57 2003
*************** finish_id_expression (tree id_expression
*** 2400,2406 ****
if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
decl = TEMPLATE_PARM_DECL (decl);
if (constant_expression_p
! && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
{
if (!allow_non_constant_expression_p)
error ("template parameter `%D' of type `%T' is not allowed in "
--- 2400,2407 ----
if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
decl = TEMPLATE_PARM_DECL (decl);
if (constant_expression_p
! && !dependent_type_p (TREE_TYPE (decl))
! && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
{
if (!allow_non_constant_expression_p)
error ("template parameter `%D' of type `%T' is not allowed in "
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/parse/nontype1.C gcc-main-new/gcc/testsuite/g++.dg/parse/nontype1.C
*** gcc-main-save/gcc/testsuite/g++.dg/parse/nontype1.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/parse/nontype1.C Mon Dec 29 17:50:06 2003
***************
*** 0 ****
--- 1,9 ----
+ // Copyright (C) 2003 Free Software Foundation
+ // Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+ // { dg-do compile }
+
+ // PR c++/13289: Incorrectly reject non-type template argument that has
+ // dependent type
+
+ template <class T, T t> class C {};
+ template <class T, T t> class D { C<T, t-1> c; };