Commit Graph

1 Commits

Author SHA1 Message Date
William S Fulton 0d88926e79 C++14/20: parse auto parameters in functions and lambdas
Adds an AUTO parameter_declarator alternative to parm_no_dox.  Placing
the new alternative in parm_no_dox rather than type_right scopes the
'auto' keyword to parameter context only, so it does not clash with
the dedicated 'storage_class AUTO declarator ...' rules at top level
and the existing %expect 7 conflict count is unchanged.

Functions whose parms include 'auto' are converted to a function
template - one invented type template parameter (named
"__dummy_auto_<N>__") per auto parm - via promote_abbreviated_template()
called from c_decl, so abbreviated function templates wrap through the
existing %template instantiation machinery.

Lambdas (which already route through parms) get the same fix
transparently and parse without choking, matching the C++14 generic
lambda form.

The function must declare an explicit (non-auto) return type for SWIG
to wrap it. The C++14 auto return restriction, (cpp14_auto_return_type
testcase) still applies.

  // C++14 generic lambda
  auto twice = [](auto x) { return x + x; };

  // C++20 abbreviated function template
  int twice(auto x) { return x + x; }
  %template(twice_int) twice<int>;

Assisted-by: Claude Code (Opus 4.7)
2026-05-12 23:04:20 +01:00