diff -u gcc/cp/constexpr.c gcc/cp/constexpr.c --- gcc/cp/constexpr.c 2019-10-03 14:53:59.268559514 +0200 +++ gcc/cp/constexpr.c 2019-10-03 14:53:59.268559514 +0200 @@ -3398,21 +3398,13 @@ { tree type_domain = TYPE_DOMAIN (optype); tree min_val = size_zero_node; - tree max_val = NULL_TREE; if (type_domain && TYPE_MIN_VALUE (type_domain)) min_val = TYPE_MIN_VALUE (type_domain); - if (type_domain && TYPE_MAX_VALUE (type_domain)) - max_val = TYPE_MAX_VALUE (type_domain); unsigned HOST_WIDE_INT el_sz = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (optype))); unsigned HOST_WIDE_INT idx = off / el_sz; unsigned HOST_WIDE_INT rem = off % el_sz; - if (tree_fits_uhwi_p (min_val) - && (max_val == NULL_TREE - /* Punt on checking VLA bounds here. */ - || TREE_CODE (max_val) != INTEGER_CST - || (tree_fits_uhwi_p (max_val) - && idx <= tree_to_uhwi (max_val)))) + if (tree_fits_uhwi_p (min_val)) { tree index = size_int (idx + tree_to_uhwi (min_val)); op = build4_loc (loc, ARRAY_REF, TREE_TYPE (optype), op, index, @@ -3422,7 +3414,7 @@ } } /* ((foo *)&struct_with_foo_field)[x] => COMPONENT_REF */ - else if (RECORD_OR_UNION_TYPE_P (optype)) + else if (TREE_CODE (optype) == RECORD_TYPE) { for (tree field = TYPE_FIELDS (optype); field; field = DECL_CHAIN (field)) reverted: --- gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C 2019-10-03 16:13:58.636977962 +0200 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C.jj 2015-11-26 10:40:59.546389024 +0100 @@ -3,4 +3,4 @@ constexpr char c[] = "hello"; constexpr const char *p = c; +constexpr char ch = *(p-1); // { dg-error "array subscript" } -constexpr char ch = *(p-1); // { dg-error "is not a constant expression" } reverted: --- gcc/testsuite/g++.dg/ubsan/pr63956.C 2019-10-03 18:57:25.541783658 +0200 +++ gcc/testsuite/g++.dg/ubsan/pr63956.C.jj 2019-06-19 10:20:12.390666122 +0200 @@ -80,7 +80,7 @@ fn5 (const int *a, int b) { if (b != 2) + b = a[b]; // { dg-error "array subscript" } - b = a[b]; // { dg-error "is not a constant expression" } return b; }