From bfbe98c7e0d570c903c89359cd25073e538a365e Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sat, 7 Dec 2019 17:35:54 +0000 Subject: [PATCH] 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 . Now it returns VIEW_CONVERT_EXPR(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. From-SVN: r279077 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/decltype73.C | 4 ++++ 4 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype73.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 582ffe0..0994815 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-12-07 Marek Polacek + + PR c++/91678 - wrong error with decltype and location wrapper. + * fold-const.c (maybe_lvalue_p): Handle VIEW_CONVERT_EXPR. + 2019-12-07 Eric Botcazou PR middle-end/90840 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c5bd45a..8e9e2999 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2598,6 +2598,7 @@ maybe_lvalue_p (const_tree x) case TARGET_EXPR: case COND_EXPR: case BIND_EXPR: + case VIEW_CONVERT_EXPR: break; default: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 460cff0..2d14412 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-07 Marek Polacek + + PR c++/91678 - wrong error with decltype and location wrapper. + * g++.dg/cpp0x/decltype73.C: New test. + 2019-12-07 Jakub Jelinek PR c++/92831 diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype73.C b/gcc/testsuite/g++.dg/cpp0x/decltype73.C new file mode 100644 index 0000000..cbe94a8 --- /dev/null +++ b/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; } -- 2.7.4