aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-01-29 15:56:00 -0500
committerJason Merrill <jason@gcc.gnu.org>2018-01-29 15:56:00 -0500
commitdcbb27dd3f494812c89b530b7dcf06cfad2ff10b (patch)
treef1222d8a891ce6f9603dc2865e26bbb939e11429
parentb07c365100c92687361aa062ecf89c49650b8930 (diff)
downloadgcc-dcbb27dd3f494812c89b530b7dcf06cfad2ff10b.zip
gcc-dcbb27dd3f494812c89b530b7dcf06cfad2ff10b.tar.gz
gcc-dcbb27dd3f494812c89b530b7dcf06cfad2ff10b.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/cvt.c5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret1.C4
3 files changed, 14 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e8b0e1e..9737987 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-29 Jason Merrill <jason@redhat.com>
+
+ 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 <polacek@redhat.com>
PR c++/83996
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 3ab3e2e..f5da08b 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 d2ee2ba..d7d244f 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;