Files
gcc-reflection/gcc/testsuite/g++.dg/cpp1y/constexpr-shift1.C
Jakub Jelinek eeb54a14c4 c++: Reject some further reinterpret casts in constexpr [PR82304, PR95307]
cxx_eval_outermost_constant_expr had a check for reinterpret_casts from
pointers (well, it checked from ADDR_EXPRs) to integral type, but that
only caught such cases at the toplevel of expressions.
As the comment said, it should be done even inside of the expressions,
but at the point of the writing e.g. pointer differences used to be a
problem.  We now have POINTER_DIFF_EXPR, so this is no longer an issue.

Had to do it just for CONVERT_EXPR, because the FE emits NOP_EXPR casts
from pointers to integrals in various spots, e.g. for the PMR & 1 tests,
though on NOP_EXPR we have the REINTERPRET_CAST_P bit that we do check,
while on CONVERT_EXPR we don't.

2020-06-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/82304
	PR c++/95307
	* constexpr.c (cxx_eval_constant_expression): Diagnose CONVERT_EXPR
	conversions from pointer types to arithmetic types here...
	(cxx_eval_outermost_constant_expr): ... instead of here.

	* g++.dg/template/pr79650.C: Expect different diagnostics and expect
	it on all lines that do pointer to integer casts.
	* g++.dg/cpp1y/constexpr-shift1.C: Expect different diagnostics.
	* g++.dg/cpp1y/constexpr-82304.C: New test.
	* g++.dg/cpp0x/constexpr-95307.C: New test.
2020-06-04 09:09:01 +02:00

10 lines
312 B
C

// { dg-do compile { target c++14 } }
constexpr int p = 1;
constexpr __PTRDIFF_TYPE__ bar (int a)
{
return ((__PTRDIFF_TYPE__) &p) << a; // { dg-error "conversion from pointer" }
}
constexpr __PTRDIFF_TYPE__ r = bar (2); // { dg-message "in .constexpr. expansion of" }
constexpr __PTRDIFF_TYPE__ s = bar (0);