For some targets, like Cortex-M on arm-none-eabi, the -fshort-enums is
enabled by default. For these targets, the test case fails as
sizeof(Alpha) < sizeof(int).
To make the test case behave identical for targets that does enable
-fshort-enums and those that does not, add -fno-short-enums in the test
case and verify that the warning is not emitted. Then also create a copy
and run the test with -fshort-enums and verify that the warning is
emitted.
Regtested on x86_64-pc-linux-gnu and arm-none-eabi.
gcc/testsuite/ChangeLog:
* g++.dg/warn/pr33738.C: Added -fno-short-enums.
* g++.dg/warn/pr33738-2.C: Duplicate g++.dg/warn/pr33738.C with
-fshort-enums and removed xfail.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
--- /dev/null
+// { dg-do run }
+// { dg-options "-O2 -Wtype-limits -fstrict-enums -fshort-enums" }
+extern void link_error (void);
+
+enum Alpha {
+ ZERO = 0, ONE, TWO, THREE
+};
+
+Alpha a2;
+
+int m1 = -1;
+int GetM1() {
+ return m1;
+}
+
+int main() {
+ a2 = static_cast<Alpha>(GetM1());
+ if (a2 == -1) { // { dg-warning "always false due" } */
+ link_error ();
+ }
+ a2 = static_cast<Alpha>(GetM1());
+ if (-1 == a2) { // { dg-warning "always false due" } */
+ link_error ();
+ }
+ return 0;
+}
+
// { dg-do run }
-// { dg-options "-O2 -Wtype-limits -fstrict-enums" }
+// { dg-prune-output "use of enum values across objects may fail" }
+// { dg-options "-O2 -Wtype-limits -fstrict-enums -fno-short-enums" }
extern void link_error (void);
enum Alpha {