C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal: Making The auto Keyword Optional in Trailing Return Types

From: Christof Meerwald <cmeerw_at_[hidden]>
Date: Wed, 19 Mar 2025 11:44:06 +0100
On Wed, Mar 19, 2025 at 04:56:34AM +0300, Fady al Dhaim via Std-Proposals wrote:
> *2. Why This Won’t Break Existing Code*
>
> This proposal is *backward-compatible* because:
>
> -
>
> auto is *already optional* in normal return types:
>
> int func();
>
> -
>
> This change is *purely syntactic*—it does not affect semantics.
> -
>
> Existing code using auto remains *fully valid*.
> auto func() -> int; // Remains valid
> auto func() -> decltype(some_expression); // Also valid
>
> Thus, this proposal only *removes an unnecessary restriction* without
> introducing breaking changes.

What about this one?

  struct x { };
  struct C { int x; };
  C *g(int = 0);
  void f(int i) {
    g()->x;
  }

Currently, "g()->x" is parsed as a function call, but "auto g()->x"
would be parsed as a function declaration.


Christof

-- 
https://cmeerw.org                             sip:cmeerw at cmeerw.org
mailto:cmeerw at cmeerw.org                   xmpp:cmeerw at cmeerw.org

Received on 2025-03-19 10:44:08