public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>,
	Jason Merrill <jason@redhat.com>,
	David Malcolm <dmalcolm@redhat.com>,
	Nathan Sidwell <nathan@acm.org>
Subject: Re: C++ PATCH for c++/91678 - wrong error with decltype and location wrapper
Date: Fri, 13 Sep 2019 02:26:00 -0000	[thread overview]
Message-ID: <20190913022601.GO14737@redhat.com> (raw)
In-Reply-To: <20190906022455.GC14737@redhat.com>

Ping.

On Thu, Sep 05, 2019 at 10:24:55PM -0400, Marek Polacek wrote:
> Compiling this testcase results in a bogus "invalid cast" error; this occurs
> since the introduction of location wrappers in finish_id_expression.
> 
> Here we are parsing the decltype expression via cp_parser_decltype_expr which
> can lead to calling various fold_* and c-family routines.  They use
> non_lvalue_loc, but that won't create a NON_LVALUE_EXPR wrapper around a location
> wrapper.
> 
> So before the location wrappers addition cp_parser_decltype_expr would return
> NON_LVALUE_EXPR <c>.  Now it returns VIEW_CONVERT_EXPR<float *>(c), but the
> STRIP_ANY_LOCATION_WRAPPER immediately following it strips the location wrapper,
> and suddenly we don't know whether we have an lvalue anymore.  And that's sad
> because then decltype produces the wrong type, causing nonsense errors.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk and 9?
> 
> 2019-09-05  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/91678 - wrong error with decltype and location wrapper.
> 	* parser.c (cp_parser_decltype): Use auto_suppress_location_wrappers
> 	sentinel.  Don't strip location wrappers.
> 
> 	* g++.dg/cpp0x/decltype73.C: New test.
> 
> diff --git gcc/cp/parser.c gcc/cp/parser.c
> index baa60b8834e..b3c7bff5988 100644
> --- gcc/cp/parser.c
> +++ gcc/cp/parser.c
> @@ -14729,8 +14729,13 @@ cp_parser_decltype (cp_parser *parser)
>        /* Do not warn about problems with the expression.  */
>        ++c_inhibit_evaluation_warnings;
>  
> +      /* Don't create wrapper nodes within decltype.  non_lvalue_loc won't
> +	 create a NON_LVALUE_EXPR wrapper around a location wrapper, and a
> +	 subsequent STRIP_ANY_LOCATION_WRAPPER would destroy the information
> +	 about lvalueness of the expression.  */
> +      auto_suppress_location_wrappers sentinel;
> +
>        expr = cp_parser_decltype_expr (parser, id_expression_or_member_access_p);
> -      STRIP_ANY_LOCATION_WRAPPER (expr);
>  
>        /* Go back to evaluating expressions.  */
>        --cp_unevaluated_operand;
> 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-13  2:26 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 [this message]
2019-09-15 14:18 ` Jason Merrill
2019-09-16 18:12   ` Marek Polacek
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=20190913022601.GO14737@redhat.com \
    --to=polacek@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathan@acm.org \
    /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).