8sa1-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr9.C
Martin Sebor abdc16c867 PR c++/67376 - [5/6 regression] Comparison with pointer to past-the-end
PR c++/67376 - [5/6 regression] Comparison with pointer to past-the-end
        of array fails inside constant expression
PR c++/70170 - [6 regression] bogus not a constant expression error comparing
        pointer to array to null
PR c++/70172 - incorrect reinterpret_cast from integer to pointer error
        on invalid constexpr initialization
PR c++/70228 - insufficient detail in diagnostics for a constexpr out of bounds
        array subscript

gcc/testsuite/ChangeLog:
2016-04-02  Martin Sebor  <msebor@redhat.com>

        PR c++/67376
        PR c++/70170
        PR c++/70172
        PR c++/70228
        * g++.dg/cpp0x/constexpr-array-ptr10.C: New test.
        * g++.dg/cpp0x/constexpr-array-ptr9.C: New test.
        * g++.dg/cpp0x/constexpr-nullptr-1.C: New test.
        * g++.dg/cpp0x/constexpr-array5.C: Adjust text of expected diagnostic.
        * g++.dg/cpp0x/constexpr-string.C: Same.
        * g++.dg/cpp0x/constexpr-wstring2.C: Same.
        * g++.dg/cpp0x/pr65398.C: Same.
        * g++.dg/ext/constexpr-vla1.C: Same.
        * g++.dg/ext/constexpr-vla2.C: Same.
        * g++.dg/ext/constexpr-vla3.C: Same.
        * g++.dg/ubsan/pr63956.C: Same.

gcc/cp/ChangeLog:
2016-04-02  Martin Sebor  <msebor@redhat.com>

        PR c++/67376
        PR c++/70170
        PR c++/70172
        PR c++/70228
        * constexpr.c (diag_array_subscript): New function.
        (cxx_eval_array_reference): Detect out of bounds array indices.

gcc/ChangeLog:
2016-04-02  Martin Sebor  <msebor@redhat.com>

        PR c++/67376
        * fold-const.c (maybe_nonzero_address): New function.
        (fold_comparison): Call it.  Fold equality and relational
        expressions involving null pointers.
        (tree_single_nonzero_warnv_p): Call maybe_nonzero_address.

From-SVN: r234698
2016-04-02 11:14:48 -06:00

58 lines
1.1 KiB
C

// PR c++/67376 - [5/6 regression] Comparison with pointer to past-the-end
// of array fails inside constant expression
// { dg-do compile { target c++11 } }
int a [2];
constexpr const int* pa[] = {
a,
a + 0,
a + 1,
a + 2,
&a [0],
&a [0] + 0,
&a [0] + 1,
&a [0] + 2,
&a [1],
&a [1] - 1,
&a [1] + 0,
&a [1] + 1,
&a [2] - 2,
&a [2] - 1,
&a [2] + 0
};
#define Assert(e) static_assert ((e), #e)
Assert (!(a == 0));
Assert (!(a == (int*)0));
Assert (!(a == nullptr));
Assert (a != 0);
Assert (a != (int*)0);
Assert (a != nullptr);
Assert (!(0 == a));
Assert (!((int*)0 == a));
Assert (!(nullptr == a));
Assert (0 != a);
Assert ((int*)0 != a);
Assert (nullptr != a);
bool constexpr test_eq (unsigned inx)
{
return inx ? pa [inx - 1] == 0 && 0 == pa [inx - 1]
&& test_eq (inx - 1) : pa [inx] == 0 && 0 == pa [inx];
}
Assert (!test_eq (sizeof pa / sizeof *pa));
bool constexpr test_ne (unsigned inx)
{
return inx ? pa [inx - 1] != 0 && 0 != pa [inx - 1]
&& test_ne (inx - 1) : pa [inx] != 0 && 0 != pa [inx];
}
Assert (test_ne (sizeof pa / sizeof *pa));