commit ea38396630703879e5416265cd66db87845f3684 Author: Jason Merrill Date: Mon Jan 29 15:52:09 2018 -0500 PR c++/68810 - wrong location for reinterpret_cast error. * cvt.c (cp_convert_to_pointer): Always build a CONVERT_EXPR when !dofold. 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;