gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr10.C
Paolo Carlini 8cb6a77590 decl.c (grok_ctor_properties): Use DECL_SOURCE_LOCATION.
/cp
2019-10-09  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grok_ctor_properties): Use DECL_SOURCE_LOCATION.
	* typeck.c (cp_build_binary_op): Use the op_location_t argument
	in many error messages.

/testsuite
2019-10-09  Paolo Carlini  <paolo.carlini@oracle.com>

	* c-c++-common/Waddress-1.c: Test locations too.
	* c-c++-common/Wpointer-compare-1.c: Likewise.
	* c-c++-common/Wshift-count-negative-1.c: Likewise.
	* c-c++-common/Wshift-count-overflow-1.c: Likewise.
	* c-c++-common/Wshift-negative-value-1.c: Likewise.
	* c-c++-common/Wshift-negative-value-2.c: Likewise.
	* c-c++-common/Wshift-negative-value-5.c: Likewise.
	* c-c++-common/pr48418.c: Likewise.
	* c-c++-common/pr65830.c: Likewise.
	* c-c++-common/pr69764.c: Likewise.
	* g++.dg/cpp0x/constexpr-array-ptr10.C: Likewise.
	* g++.dg/cpp0x/nullptr37.C: Likewise.
	* g++.dg/template/crash126.C: Likewise.
	* g++.dg/template/crash129.C: Likewise.
	* g++.dg/warn/Wextra-3.C: Likewise.
	* g++.dg/warn/Wfloat-equal-1.C: Likewise.
	* g++.dg/warn/Wstring-literal-comparison-1.C: Likewise.
	* g++.dg/warn/Wstring-literal-comparison-2.C: Likewise.
	* g++.dg/warn/pointer-integer-comparison.C: Likewise.
	* g++.old-deja/g++.jason/crash8.C: Likewise.

From-SVN: r276763
2019-10-09 17:17:19 +00:00

112 lines
4.3 KiB
C

// PR c++/67376 - [5/6 regression] Comparison with pointer to past-the-end
// of array fails inside constant expression
// This test verifies the aspect of the bug raised in comment #10,
// specifically comparing pointers to null. The basic regression test
// is in g++.dg/cpp0x/constexpr-67376.C.
// Note also that while the description of the bug talks about pointers
// pointing past the end of arrays but the prolem is more general than
// that and involves all constexpr object pointers.
// { dg-do compile { target c++11 } }
// { dg-additional-options "-Wall -Wextra -fdelete-null-pointer-checks" }
namespace A {
extern int i;
constexpr int *p0 = &i;
constexpr bool b0 = p0; // { dg-warning "address of .A::i." }
constexpr bool b1 = p0 == 0; // { dg-warning "address of .A::i." }
constexpr bool b2 = p0 != 0; // { dg-warning "address of .A::i." }
constexpr bool b3 = p0 < 0; // { dg-warning "25:ordered comparison" }
constexpr bool b4 = p0 <= 0; // { dg-warning "25:ordered comparison" }
constexpr bool b5 = p0 > 0; // { dg-warning "25:ordered comparison" }
constexpr bool b6 = p0 >= 0; // { dg-warning "25:ordered comparison" }
constexpr bool b7 = !p0; // { dg-warning "address of .A::i." }
constexpr bool b8 = 0 == p0; // { dg-warning "address of .A::i." }
constexpr bool b9 = 0 != p0; // { dg-warning "address of .A::i." }
constexpr bool b10 = 0 < p0; // { dg-warning "24:ordered comparison" }
constexpr bool b11 = 0 <= p0; // { dg-warning "24:ordered comparison" }
constexpr bool b12 = 0 > p0; // { dg-warning "24:ordered comparison" }
constexpr bool b13 = 0 >= p0; // { dg-warning "24:ordered comparison" }
}
namespace B {
// PR c++/70172 - incorrect reinterpret_cast from integer to pointer
// error on invalid constexpr initialization
struct S { int a, b[1]; } s;
constexpr S *p0 = &s;
constexpr int *q0 = p0->b; // { dg-bogus "reinterpret_cast from integer to pointer" }
}
namespace WeakRefTest1 {
extern __attribute__ ((weak)) int i;
constexpr int *p0 = &i;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wextra"
// Suppress warning: ordered comparison of pointer with integer zero
constexpr bool b0 = p0; // { dg-error "not a constant expression" }
constexpr bool b1 = p0 == 0; // { dg-error "not a constant expression" }
constexpr bool b2 = p0 != 0; // { dg-error "not a constant expression" }
constexpr bool b4 = p0 <= 0; // { dg-error "not a constant expression" }
constexpr bool b5 = p0 > 0; // { dg-error "not a constant expression" }
constexpr bool b7 = !p0; // { dg-error "not a constant expression" }
constexpr bool b8 = 0 == p0; // { dg-error "not a constant expression" }
constexpr bool b9 = 0 != p0; // { dg-error "not a constant expression" }
constexpr bool b10 = 0 < p0; // { dg-error "not a constant expression" }
constexpr bool b13 = 0 >= p0; // { dg-error "not a constant expression" }
// The following are accepted as constant expressions due to bug c++/70196.
constexpr bool b3 = p0 < 0;
constexpr bool b6 = p0 >= 0;
constexpr bool b11 = 0 <= p0;
constexpr bool b12 = 0 > p0;
#pragma GCC diagnostic pop
}
namespace WeakRefTest2 {
extern __attribute__ ((weak)) int i;
constexpr int *p1 = &i + 1;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wextra"
// Suppress warning: ordered comparison of pointer with integer zero
constexpr bool b0 = p1; // { dg-error "not a constant expression" }
constexpr bool b1 = p1 == 0; // { dg-error "not a constant expression" }
constexpr bool b2 = p1 != 0; // { dg-error "not a constant expression" }
constexpr bool b4 = p1 <= 0; // { dg-error "not a constant expression" }
constexpr bool b5 = p1 > 0; // { dg-error "not a constant expression" }
constexpr bool b7 = !p1; // { dg-error "not a constant expression" }
constexpr bool b8 = 0 == p1; // { dg-error "not a constant expression" }
constexpr bool b9 = 0 != p1; // { dg-error "not a constant expression" }
constexpr bool b10 = 0 < p1; // { dg-error "not a constant expression" }
constexpr bool b13 = 0 >= p1; // { dg-error "not a constant expression" }
// The following are accepted as constant expressions due to bug c++/70196.
// constexpr bool b3 = p1 < 0;
// constexpr bool b6 = p1 >= 0;
// constexpr bool b11 = 0 <= p1;
// constexpr bool b12 = 0 > p1;
#pragma GCC diagnostic pop
}