https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91678

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Sat Dec  7 17:35:54 2019
New Revision: 279077

URL: https://gcc.gnu.org/viewcvs?rev=279077&root=gcc&view=rev
Log:
        PR c++/91678 - wrong error with decltype and location wrapper.

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.

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

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

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/decltype73.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Reply via email to