Ok for trunk and releases/gcc-14? Changes since v1:
- Changed original test case to use -fno-short-enums. - Added pruning of "use of enum values across objects may fail" warnings. - Created a copy of the original test case and added -fshort-enums and removed the xfail. -- 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.svens...@foss.st.com> --- gcc/testsuite/g++.dg/warn/pr33738-2.C | 27 +++++++++++++++++++++++++++ gcc/testsuite/g++.dg/warn/pr33738.C | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/pr33738-2.C diff --git a/gcc/testsuite/g++.dg/warn/pr33738-2.C b/gcc/testsuite/g++.dg/warn/pr33738-2.C new file mode 100644 index 00000000000..84bbdaeecc7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr33738-2.C @@ -0,0 +1,27 @@ +// { 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; +} + diff --git a/gcc/testsuite/g++.dg/warn/pr33738.C b/gcc/testsuite/g++.dg/warn/pr33738.C index 73e98d5e083..17ef158e56e 100644 --- a/gcc/testsuite/g++.dg/warn/pr33738.C +++ b/gcc/testsuite/g++.dg/warn/pr33738.C @@ -1,5 +1,6 @@ // { 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 { -- 2.25.1