On 8/7/24 9:00 PM, Arsen Arsenović wrote:
Jason Merrill <ja...@redhat.com> writes:

On 8/7/24 7:31 PM, Arsen Arsenović wrote:
Enlargening the function-specific data block is not great.

Indeed, I think it would be better to search DECL_SAVED_TREE for a RETURN_STMT
once we've decided to give an error.

The trouble with that is that finish_return_stmt currently uses
input_location as the location for the entire return expr, so the
location ends up being after the entire return value.

I've hacked in a way to provide a different location to
finih_return_stmt, when applying it like below, the produced result is
the first result in the original email:

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 6cfe42f3bdd6..44b45f16b026 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -14965,12 +14965,15 @@ cp_parser_jump_statement (cp_parser* parser, tree 
&std_attrs)
/* Build the return-statement, check co-return first, since type
          deduction is not valid there.  */
+       auto l = make_location (token->location,
+                               token->location,
+                               input_location);
        if (keyword == RID_CO_RETURN)
         statement = finish_co_return_stmt (token->location, expr);
        else if (FNDECL_USED_AUTO (current_function_decl) && in_discarded_stmt)
         /* Don't deduce from a discarded return statement.  */;
        else
-        statement = finish_return_stmt (expr);
+        statement = finish_return_stmt (expr, l);
        /* Look for the final `;'.  */
        cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
        }

... without this change (so, using input_location), the result is:

test.cc:38:11: error: a ‘return’ statement is not allowed in coroutine; did you 
mean ‘co_return’?
    38 |   return {};
       |           ^

... which is not the best.  That's the change I'm referring to in the
original post that I haven't ran the testsuite on.  Changing that
location allows for simply searching DECL_SAVED_TREE (fndecl), though,
and getting a good location out of it.

Sounds good.

Jason

Reply via email to