[Bug c++/82304] GCC compiles constexpr function with double reinterpret_cast in a constant context

2020-06-04 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82304

--- Comment #3 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:eeb54a14c48f543857f561556ab1fc49dc21af26

commit r11-893-geeb54a14c48f543857f561556ab1fc49dc21af26
Author: Jakub Jelinek 
Date:   Thu Jun 4 09:09:01 2020 +0200

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  

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.

[Bug c++/82304] GCC compiles constexpr function with double reinterpret_cast in a constant context

2019-11-28 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82304

Jonathan Wakely  changed:

   What|Removed |Added

   Last reconfirmed|2017-09-25 00:00:00 |2019-11-28

--- Comment #2 from Jonathan Wakely  ---
Reduced:

constexpr const char* testfunc(const char* p)
{
  auto l = reinterpret_cast(p);
  ++l
  return reinterpret_cast(l);
}

constexpr auto s = testfunc("Hello");

I assume the problem here and in Bug 92411 is that the compiler is folding the
casts away.

[Bug c++/82304] GCC compiles constexpr function with double reinterpret_cast in a constant context

2017-09-24 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82304

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||accepts-invalid
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-09-25
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---
Confirmed.