Hi,
in this issue (and its duplicate) the complain is that for cases like:
enum E : unsigned { e = -1 };
saying in the error message that the enumerator is *too large* can be
rather misleading. It seems to me that replacing that with "... outside
the range..." (we already use this form in at least another place) it's
a good improvement. ICC behave similarly, clang++ uses the more
technical "cannot be narrowed".
Tested x86_64-linux.
Thanks!
Paolo.
///////////////////////
/cp
2013-05-04 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/53745
* decl.c (build_enumerator): Improve error message.
/testsuite
2013-05-04 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/53745
* g++.dg/cpp0x/enum27.C: New.
* g++.dg/cpp0x/enum_base.C: Adjust.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 198593)
+++ cp/decl.c (working copy)
@@ -12847,8 +12847,8 @@ incremented enumerator value is too large for %<lo
&& TREE_CODE (value) == INTEGER_CST)
{
if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
- error ("enumerator value %E is too large for underlying type
%<%T%>",
- value, ENUM_UNDERLYING_TYPE (enumtype));
+ error ("enumerator value %E is outside the range of underlying "
+ "type %<%T%>", value, ENUM_UNDERLYING_TYPE (enumtype));
/* Convert the value to the appropriate type. */
value = convert (ENUM_UNDERLYING_TYPE (enumtype), value);
Index: testsuite/g++.dg/cpp0x/enum27.C
===================================================================
--- testsuite/g++.dg/cpp0x/enum27.C (revision 0)
+++ testsuite/g++.dg/cpp0x/enum27.C (working copy)
@@ -0,0 +1,4 @@
+// PR c++/53745
+// { dg-do compile { target c++11 } }
+
+enum E : unsigned { e = -1 }; // { dg-error "outside the range" }
Index: testsuite/g++.dg/cpp0x/enum_base.C
===================================================================
--- testsuite/g++.dg/cpp0x/enum_base.C (revision 198593)
+++ testsuite/g++.dg/cpp0x/enum_base.C (working copy)
@@ -6,11 +6,11 @@ enum E1 : char { };
enum E2 : signed const short { };
enum E3 : uvlonglong { };
enum E4 : char {
- val = 500 // { dg-error "too large" }
+ val = 500 // { dg-error "outside the range" }
};
enum class E5 {
- val = (unsigned long long)-1 // { dg-error "too large" }
+ val = (unsigned long long)-1 // { dg-error "outside the range" }
};
typedef float Float;