[C++ PATCH] Avoid constexpr garbage for implicit conversion to void.

Jakub Jelinek jakub@redhat.com
Wed Jun 19 08:23:00 GMT 2019


On Tue, Jun 18, 2019 at 12:07:38PM -0400, Jason Merrill wrote:
> commit 8f67898b9bd5924f3dd5218164df62ada10ea428
> Author: Jason Merrill <jason@redhat.com>
> Date:   Sat Jun 15 23:59:55 2019 -0400
> 
>     Consolidate constexpr array handling.
>     
>             * constexpr.c (eval_and_check_array_index): Split out from...
>             (cxx_eval_array_reference): ...here.
>             (cxx_eval_store_expression): Use it here, too.
>             (diag_array_subscript): Take location.  Strip location wrapper.

The r272430 change introduced:
+FAIL: g++.dg/ubsan/pr63956.C   -O0  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63956.C   -O1  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63956.C   -O2  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63956.C   -O2 -flto  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63956.C   -O2 -flto -flto-partition=none  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63956.C   -O3 -g  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63956.C   -Os  (test for excess errors)
>From what I can see, it just changed the location of the diagnostics, like:
@@ -29,17 +29,23 @@ pr63956.C:72:11: error: ‘(7.0e+0f / 0.
    72 |     a = a / b; // { dg-error "is not a constant expression" }
       |         ~~^~~
 pr63956.C:89:24:   in ‘constexpr’ expansion of ‘fn5(((const int*)(& m1)), 4)’
-pr63956.C:89:30: error: array subscript value ‘4’ is outside the bounds of array type ‘const int [4]’
-   89 | constexpr int m3 = fn5 (m1, 4); // { dg-error "array subscript|in .constexpr. expansion of " }
-      |                              ^
+pr63956.C:83:12: error: array subscript value ‘4’ is outside the bounds of array ‘m1’ of type ‘const int [4]’
+   83 |     b = a[b];
+      |         ~~~^
+pr63956.C:87:15: note: declared here
+   87 | constexpr int m1[4] = { 1, 2, 3, 4 };
+      |               ^~
 pr63956.C:109:24:   in ‘constexpr’ expansion of ‘fn7(0, 8)’
 pr63956.C:109:43: error: dereferencing a null pointer
   109 | constexpr int n3 = fn7 ((const int *) 0, 8);  // { dg-error "null pointer|in .constexpr. expansion of " }
       |                                           ^
 pr63956.C:119:24:   in ‘constexpr’ expansion of ‘fn8(10)’
-pr63956.C:119:27: error: array subscript value ‘10’ is outside the bounds of array type ‘const int [10]’
-  119 | constexpr int o2 = fn8 (10); // { dg-error "array subscript|in .constexpr. expansion of " }
-      |                           ^
+pr63956.C:115:13: error: array subscript value ‘10’ is outside the bounds of array ‘g’ of type ‘const int [10]’
+  115 |   return g[i];
+      |          ~~~^
+pr63956.C:114:17: note: declared here
+  114 |   constexpr int g[10] = { };
+      |                 ^
 pr63956.C:130:24:   in ‘constexpr’ expansion of ‘fn9(2147483647, 1)’
 pr63956.C:130:39: error: overflow in constant expression [-fpermissive]
   130 | constexpr int p2 = fn9 (__INT_MAX__, 1); // { dg-error "overflow in constant expression|in .constexpr. expansion of " }

So, I've committed following patch as obvious after testing it on
x86_64-linux -m32/-m64.

2019-06-19  Jakub Jelinek  <jakub@redhat.com>

	* g++.dg/ubsan/pr63956.C: Adjust expected diagnostics.

--- gcc/testsuite/g++.dg/ubsan/pr63956.C.jj	2019-05-20 11:39:25.003963953 +0200
+++ gcc/testsuite/g++.dg/ubsan/pr63956.C	2019-06-19 10:20:12.390666122 +0200
@@ -80,13 +80,13 @@ constexpr int
 fn5 (const int *a, int b)
 {
   if (b != 2)
-    b = a[b];
+    b = a[b]; // { dg-error "array subscript" }
   return b;
 }
 
 constexpr int m1[4] = { 1, 2, 3, 4 };
 constexpr int m2 = fn5 (m1, 3);
-constexpr int m3 = fn5 (m1, 4); // { dg-error "array subscript|in .constexpr. expansion of " }
+constexpr int m3 = fn5 (m1, 4); // { dg-message "in .constexpr. expansion of " }
 
 constexpr int
 fn6 (const int &a, int b)
@@ -112,11 +112,11 @@ constexpr int
 fn8 (int i)
 {
   constexpr int g[10] = { };
-  return g[i];
+  return g[i]; // { dg-error "array subscript" }
 }
 
 constexpr int o1 = fn8 (9);
-constexpr int o2 = fn8 (10); // { dg-error "array subscript|in .constexpr. expansion of " }
+constexpr int o2 = fn8 (10); // { dg-message "in .constexpr. expansion of " }
 
 constexpr int
 fn9 (int a, int b)


	Jakub



More information about the Gcc-patches mailing list