From: Marek Polacek Date: Tue, 14 May 2024 17:48:30 +0000 (-0400) Subject: c++: add test for DR 2855 X-Git-Tag: basepoints/gcc-16~9038 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cefe91b74f65f0db71472e01ca83c69e2cd81cc;p=thirdparty%2Fgcc.git c++: add test for DR 2855 Let int8_t x = 127; This DR says that while x++; invokes UB, ++x; does not. The resolution was to make the first one valid. The following test verifies that we don't report any errors in a constexpr context. DR 2855 gcc/testsuite/ChangeLog: * g++.dg/DRs/dr2855.C: New test. --- diff --git a/gcc/testsuite/g++.dg/DRs/dr2855.C b/gcc/testsuite/g++.dg/DRs/dr2855.C new file mode 100644 index 000000000000..b4609ceaa158 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2855.C @@ -0,0 +1,16 @@ +// DR 2855, Undefined behavior in postfix increment +// { dg-do compile { target c++14 } } + +using int8_t = signed char; + +constexpr int +f () +{ + int8_t x = 127; + x++; + int8_t z = 127; + ++z; + return x + z; +} + +constexpr int i = f();