public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH for c++/91678 - wrong error with decltype and location wrapper
Date: Mon, 16 Sep 2019 18:12:00 -0000	[thread overview]
Message-ID: <20190916181227.GQ14737@redhat.com> (raw)
In-Reply-To: <1960c4f6-2d6f-f62c-e985-3885583110d6@redhat.com>

On Sun, Sep 15, 2019 at 10:18:29AM -0400, Jason Merrill wrote:
> On 9/5/19 9:24 PM, Marek Polacek wrote:
> > They use
> > non_lvalue_loc, but that won't create a NON_LVALUE_EXPR wrapper around a location
> > wrapper.
> 
> That seems like the bug. maybe_lvalue_p should be true for
> VIEW_CONVERT_EXPR.

That makes sense but it breaks in tsubst_* which doesn't expect a
NON_LVALUE_EXPR wrapped around a location wrapper.  Perhaps we want to handle
it like this.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-09-16  Marek Polacek  <polacek@redhat.com>

	PR c++/91678 - wrong error with decltype and location wrapper.
	* pt.c (tsubst_copy): Handle NON_LVALUE_EXPRs wrapped around a location
	wrapper. 

	* fold-const.c (maybe_lvalue_p): Handle VIEW_CONVERT_EXPR.

	* g++.dg/cpp0x/decltype73.C: New test.

diff --git gcc/cp/pt.c gcc/cp/pt.c
index 9de1b8fec97..4bd77ac2578 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -15786,8 +15786,16 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 		  return op;
 		}
 	    }
-	  /* We shouldn't see any other uses of these in templates.  */
-	  gcc_unreachable ();
+	  /* We can get a NON_LVALUE_EXPR wrapped around a location wrapper.  */
+	  else if (code == NON_LVALUE_EXPR && location_wrapper_p (op))
+	    {
+	      tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+	      op = tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl);
+	      return build1 (code, type, op);
+	    }
+	  else
+	    /* We shouldn't see any other uses of these in templates.  */
+	    gcc_unreachable ();
 	}
 
     case CAST_EXPR:
diff --git gcc/fold-const.c gcc/fold-const.c
index a99dafec589..6d955a76f87 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -2594,6 +2594,7 @@ maybe_lvalue_p (const_tree x)
   case TARGET_EXPR:
   case COND_EXPR:
   case BIND_EXPR:
+  case VIEW_CONVERT_EXPR:
     break;
 
   default:
diff --git gcc/testsuite/g++.dg/cpp0x/decltype73.C gcc/testsuite/g++.dg/cpp0x/decltype73.C
new file mode 100644
index 00000000000..cbe94a898e3
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/decltype73.C
@@ -0,0 +1,4 @@
+// PR c++/91678 - wrong error with decltype and location wrapper.
+// { dg-do compile { target c++11 } }
+
+float* test(float* c) { return (decltype(c + 0))(float*)c; }

  reply	other threads:[~2019-09-16 18:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06  2:25 Marek Polacek
2019-09-13  2:26 ` Marek Polacek
2019-09-15 14:18 ` Jason Merrill
2019-09-16 18:12   ` Marek Polacek [this message]
2019-09-18  3:59     ` Jason Merrill
2019-12-07  0:19       ` Marek Polacek
2019-12-07  4:03         ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190916181227.GQ14737@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).