decl.c (build_enumerator): Don't perform integral promotions on non-integral constants.
authorJason Merrill <jason@redhat.com>
Thu, 10 Feb 2011 16:30:08 +0000 (11:30 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 10 Feb 2011 16:30:08 +0000 (11:30 -0500)
* decl.c (build_enumerator): Don't perform integral promotions on
non-integral constants.

From-SVN: r170008

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/regress/ext-label10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/label10.C

index 7d9667d4392c1f02559f681ae739b66fbb5e2b55..20b0d4be65f1efbf02cceced2cdf6c807f923f82 100644 (file)
@@ -1,5 +1,8 @@
 2011-02-09  Jason Merrill  <jason@redhat.com>
 
+       * decl.c (build_enumerator): Don't perform integral promotions on
+       non-integral constants.
+
        * cvt.c (convert_to_void): Handle null op1.
 
        * class.c (type_has_constexpr_default_constructor): Make sure the
index 6a13cc474ae2d7010c0ba39eb5d65f3d37a687b0..866069dd3e71b208e8764dbb45c258c4f4bd8f8b 100644 (file)
@@ -11869,7 +11869,8 @@ build_enumerator (tree name, tree value, tree enumtype, location_t loc)
        {
          value = cxx_constant_value (value);
 
-         if (TREE_CODE (value) == INTEGER_CST)
+         if (TREE_CODE (value) == INTEGER_CST
+             && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
            {
              value = perform_integral_promotions (value);
            }
index 97d2cafb86a6ba328db9cee25fba1e12d9000287..dc522e3e84618756dfb962f946b30302dc74a3f3 100644 (file)
@@ -1,5 +1,8 @@
 2011-02-09  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/ext/label10.C: Adjust for C++0x mode.
+       * g++.dg/cpp0x/regress/ext-label10.C: Copy it.
+
        * g++.dg/cpp0x/regress/ext-cond1.C: Copy from ext/cond1.C.
 
        * g++.dg/cpp0x/regress/abi-empty7.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/ext-label10.C b/gcc/testsuite/g++.dg/cpp0x/regress/ext-label10.C
new file mode 100644 (file)
index 0000000..652d94a
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/33836
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+template<int N> struct A
+{
+  enum { M = && N };   // { dg-error "referenced outside|cannot appear in|not an integer constant" }
+};
+
+A<0> a;
+
+void foo ()
+{
+  __label__ P;
+  enum { O = && P };   // { dg-error "cannot appear in|not an integer constant" }
+  P:;
+}
index 735fe060bbcb8141ad809adc10480aa5548c3e16..632b2426ed51c2934f04eb249a71728422a9bdc5 100644 (file)
@@ -1,10 +1,10 @@
 // PR c++/33836
 // { dg-do compile }
-// { dg-options "-std=gnu++98" }
+// { dg-options "" }
 
 template<int N> struct A
 {
-  enum { M = && N };   // { dg-error "referenced outside|cannot appear in" }
+  enum { M = && N };   // { dg-error "referenced outside|cannot appear in|not an integer constant" }
 };
 
 A<0> a;
@@ -12,6 +12,6 @@ A<0> a;
 void foo ()
 {
   __label__ P;
-  enum { O = && P };   // { dg-error "cannot appear in" }
+  enum { O = && P };   // { dg-error "cannot appear in|not an integer constant" }
   P:;
 }