Slightly better decltype() support for expressions

decltype now accepts C++ expressions instead of just an ID, such as:

  int i,j;
  ...  decltype(i+j) ...
  ...  decltype(&i) ...

These result in a warning for non-trivial expressions which SWIG cannot evaluate:

  Warning 344: Unable to deduce decltype for 'i+j'.

See 'Type Inference' in CPlusPlus.html for workarounds.

Issue #1589
Issue #1590
This commit is contained in:
William S Fulton 2022-11-26 01:16:20 +00:00
commit 2a1711e436
8 changed files with 85 additions and 14 deletions

View file

@ -6241,11 +6241,12 @@ type_right : primitive_type { $$ = $1;
}
;
decltype : DECLTYPE LPAREN idcolon RPAREN {
Node *n = Swig_symbol_clookup($3,0);
decltype : DECLTYPE LPAREN expr RPAREN {
Node *n = Swig_symbol_clookup($3.val, 0);
if (!n) {
Swig_error(cparse_file, cparse_line, "Identifier %s not defined.\n", $3);
$$ = $3;
Swig_warning(WARN_CPP11_DECLTYPE, cparse_file, cparse_line, "Unable to deduce decltype for '%s'.\n", $3.val);
$$ = NewStringf("decltype(%s)", $3.val);
} else {
$$ = Getattr(n, "type");
}

View file

@ -99,6 +99,7 @@
#define WARN_CPP11_ALIAS_DECLARATION 341 /* redundant now */
#define WARN_CPP11_ALIAS_TEMPLATE 342 /* redundant now */
#define WARN_CPP11_VARIADIC_TEMPLATE 343
#define WARN_CPP11_DECLTYPE 344
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */