From dcbb27dd3f494812c89b530b7dcf06cfad2ff10b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 29 Jan 2018 15:56:00 -0500 Subject: [PATCH] PR c++/68810 - wrong location for reinterpret_cast error. * cvt.c (cp_convert_to_pointer): Always build a CONVERT_EXPR when !dofold. From-SVN: r257161 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cvt.c | 5 +++++ gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret1.C | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e8b0e1e140a..973798769a4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-01-29 Jason Merrill + + PR c++/68810 - wrong location for reinterpret_cast error. + * cvt.c (cp_convert_to_pointer): Always build a CONVERT_EXPR when + !dofold. + 2018-01-29 Marek Polacek PR c++/83996 diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 3ab3e2e2b40..f5da08bbee2 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -239,6 +239,11 @@ cp_convert_to_pointer (tree type, tree expr, bool dofold, gcc_assert (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (expr))) == GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type))); + /* FIXME needed because convert_to_pointer_maybe_fold still folds + conversion of constants. */ + if (!dofold) + return build1 (CONVERT_EXPR, type, expr); + return convert_to_pointer_maybe_fold (type, expr, dofold); } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret1.C index d2ee2bac223..d7d244f752d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret1.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret1.C @@ -16,7 +16,9 @@ public: constexpr static Inner & getInner() /* I am surprised this is considered a constexpr */ - { return *((Inner *)4); } // { dg-error "reinterpret_cast" } + { + return *((Inner *)4); // { dg-error "reinterpret_cast" } + } }; B B::instance; -- 2.30.2