Tested x86_64-pc-linux-gnu, OK to add such a test?

-- >8 --
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.
---
 gcc/testsuite/g++.dg/DRs/dr2855.C | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/DRs/dr2855.C

diff --git a/gcc/testsuite/g++.dg/DRs/dr2855.C 
b/gcc/testsuite/g++.dg/DRs/dr2855.C
new file mode 100644
index 00000000000..b4609ceaa15
--- /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();

base-commit: c290e6a0b7a9de5692963affc6627a4af7dc2411
-- 
2.45.0

Reply via email to