Hi,
in the audit trail of this *old* PR, which is about the miscompilation of:
char const c = 'q';
enum
{
x = c,
y = sizeof(x)
};
int test[y == sizeof(char) ? 1 : -1];
Andrew noticed that the problem is in the perform_integral_promotions
call at the beginning of build_enumerator. Now, the "funny" thing is, I
don't see why we should be calling it at all! Thus I applied the below
and booted it all languages (minus Ada) on x86_64-linux multilib and
tested C/C++ (the other languages in progress). Can you imagine a reason
why it may not be Ok?
Thanks,
Paolo.
//////////////////////
/cp
2012-01-01 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/16603
* decl.c (build_enumerator): Don't call perform_integral_promotions
on the value.
/testsuite
2012-01-01 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/16603
* g++.dg/parse/enum8.C: New.
Index: testsuite/g++.dg/parse/enum8.C
===================================================================
--- testsuite/g++.dg/parse/enum8.C (revision 0)
+++ testsuite/g++.dg/parse/enum8.C (revision 0)
@@ -0,0 +1,11 @@
+// PR c++/16603
+
+char const c = 'q';
+
+enum
+ {
+ x = c,
+ y = sizeof(x)
+ };
+
+int test[y == sizeof(char) ? 1 : -1];
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 182769)
+++ cp/decl.c (working copy)
@@ -12369,14 +12369,11 @@ build_enumerator (tree name, tree value, tree enum
{
value = cxx_constant_value (value);
- if (TREE_CODE (value) == INTEGER_CST
- && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
+ if (TREE_CODE (value) != INTEGER_CST
+ || ! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
{
- value = perform_integral_promotions (value);
- }
- else
- {
- error ("enumerator value for %qD is not an integer constant",
name);
+ error ("enumerator value for %qD is not an integer constant",
+ name);
value = NULL_TREE;
}
}