]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: add test for DR 2855
authorMarek Polacek <polacek@redhat.com>
Tue, 14 May 2024 17:48:30 +0000 (13:48 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 15 May 2024 15:28:37 +0000 (11:28 -0400)
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 [new file with mode: 0644]

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