aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>2003-12-16 15:54:28 +0000
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>2003-12-16 15:54:28 +0000
commit931a9c05c2c373fc1b7a52e9e2d27718e2395896 (patch)
tree5afd8cce9ceab35df290769d4595b8a5cdf5d96d /gcc
parentcd852e4d70875d93d0f1fc57946e14f885468a31 (diff)
downloadgcc-931a9c05c2c373fc1b7a52e9e2d27718e2395896.zip
gcc-931a9c05c2c373fc1b7a52e9e2d27718e2395896.tar.gz
gcc-931a9c05c2c373fc1b7a52e9e2d27718e2395896.tar.bz2
semantics.c (finish_id_expression): Refactor the code to handle template parameters...
* semantics.c (finish_id_expression): Refactor the code to handle template parameters, and emit a more informative error message when they are used within non integral constant expressions. From-SVN: r74700
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/semantics.c48
2 files changed, 37 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 573604f..4a19573 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-16 Giovanni Bajo <giovannibajo@gcc.gnu.org>
+
+ * semantics.c (finish_id_expression): Refactor the code to handle
+ template parameters, and emit a more informative error message
+ when they are used within non integral constant expressions.
+
2003-12-16 Nathan Sidwell <nathan@codesourcery.com>
PR c++/13387
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 574c9b0..a33a540 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2392,12 +2392,30 @@ finish_id_expression (tree id_expression,
}
/* If the name resolved to a template parameter, there is no
- need to look it up again later. Similarly, we resolve
- enumeration constants to their underlying values. */
- if (TREE_CODE (decl) == CONST_DECL)
+ need to look it up again later. */
+ if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
+ || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
{
*idk = CP_ID_KIND_NONE;
- if (DECL_TEMPLATE_PARM_P (decl) || !processing_template_decl)
+ 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 "
+ "an integral constant expression because it is not of "
+ "integral or enumeration type", decl, TREE_TYPE (decl));
+ *non_constant_expression_p = true;
+ }
+ return DECL_INITIAL (decl);
+ }
+ /* Similarly, we resolve enumeration constants to their
+ underlying values. */
+ else if (TREE_CODE (decl) == CONST_DECL)
+ {
+ *idk = CP_ID_KIND_NONE;
+ if (!processing_template_decl)
return DECL_INITIAL (decl);
return decl;
}
@@ -2516,21 +2534,17 @@ finish_id_expression (tree id_expression,
}
/* Only certain kinds of names are allowed in constant
- expression. Enumerators have already been handled above. */
+ expression. Enumerators and template parameters
+ have already been handled above. */
if (constant_expression_p)
{
- /* Non-type template parameters of integral or enumeration
- type are OK. */
- if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX
- && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
- ;
- /* Const variables or static data members of integral or
- enumeration types initialized with constant expressions
- are OK. */
- else if (TREE_CODE (decl) == VAR_DECL
- && CP_TYPE_CONST_P (TREE_TYPE (decl))
- && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))
- && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
+ /* Const variables or static data members of integral or
+ enumeration types initialized with constant expressions
+ are OK. */
+ if (TREE_CODE (decl) == VAR_DECL
+ && CP_TYPE_CONST_P (TREE_TYPE (decl))
+ && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))
+ && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
;
else
{