public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/68810, wrong diagnostic location with reinterpret_cast
@ 2018-01-29 21:10 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2018-01-29 21:10 UTC (permalink / raw)
  To: gcc-patches List; +Cc: David Malcolm

[-- Attachment #1: Type: text/plain, Size: 241 bytes --]

Here, the problem was that convert_to_pointer_maybe_fold doesn't
entirely respect the dofold argument, and folds anyway if the argument
is constant.  In this case we really don't want folding.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 68810.diff --]
[-- Type: text/plain, Size: 1430 bytes --]

commit ea38396630703879e5416265cd66db87845f3684
Author: Jason Merrill <jason@redhat.com>
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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-01-29 20:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-29 21:10 C++ PATCH for c++/68810, wrong diagnostic location with reinterpret_cast Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).