diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-11-26 01:16:20 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-11-26 01:16:20 +0000 |
commit | 2a1711e4364afe0250282e032650e3ac543e73a3 (patch) | |
tree | 01e2834a42632906be447c6dea1c72a25485a362 /Doc | |
parent | 9b91b24d6be0c5296b08b527b70e6abd5507b3c2 (diff) | |
download | swig-2a1711e4364afe0250282e032650e3ac543e73a3.tar.gz |
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
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/Manual/CPlusPlus11.html | 35 | ||||
-rw-r--r-- | Doc/Manual/Warnings.html | 3 |
2 files changed, 34 insertions, 4 deletions
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index db47ee9dc..50402cefd 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -720,18 +720,45 @@ AltStruct var2{2, 4.3}; // calls the constructor <H3><a name="CPlusPlus11_type_inference">7.2.6 Type inference</a></H3> -<p>SWIG supports <tt>decltype()</tt> with some limitations. Single -variables are allowed, however, expressions are not supported yet. For +<p>SWIG supports <tt>decltype()</tt> with limitations. Single +variables are allowed, however, non-trivial expressions are not supported very well. For example, the following code will work:</p> <div class="code"><pre> int i; decltype(i) j; </pre></div> -<p>However, using an expression inside the decltype results in syntax error:</p> +<p>SWIG is able to deduce that the variable, <tt>i</tt>, is type <tt>int</tt>. +</p> + +<p> +Using a non-trivial expression for the decltype results in a warning:</p> +<div class="code"><pre> +int i; int j; +decltype(i+j) k; // Warning 344: Unable to deduce decltype for 'i+j'. +</pre></div> + +<p> +This warning should be viewed as a prompt to add in a manual ignore of the variable/function as +in most cases the generated code will not compile. +For the example above, ignore the symbol that uses decltype and perhaps additionally +suppress the warning as follows: +</p> + +<div class="code"><pre> +#pragma SWIG nowarn=SWIGWARN_CPP11_DECLTYPE +%ignore k; +</pre></div> + +<p> +If an ignore is not acceptable, a workaround is to redefine the symbol with the actual type, for example: +</p> + <div class="code"><pre> +int k; // define k with the actual type +%ignore k; // ignore the real definition of k int i; int j; -decltype(i+j) k; // syntax error +decltype(i+j) k; // Warning 344: Unable to deduce decltype for 'i+j'. </pre></div> <p>SWIG does not support <tt>auto</tt> as a type specifier for variables, only diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 9d5361dae..1cdf37ec2 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -438,6 +438,9 @@ example.i(4) : Syntax error in input(1). <li>325. Nested <em>kind</em> not currently supported (<em>name</em> ignored). <li>326. Deprecated %extend name used - the <em>kind</em> name '<em>name</em>' should be used instead of the typedef name '<em>name</em>'. <li>327. Extern template ignored. +<li>340. Lambda expressions and closures are not fully supported yet. +<li>343. Only the first variadic template argument is currently supported. +<li>344. Unable to deduce decltype for '<em>expr</em>'. <li>350. operator new ignored. <li>351. operator delete ignored. <li>352. operator+ ignored. |