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 /Examples | |
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 'Examples')
-rw-r--r-- | Examples/test-suite/common.mk | 1 | ||||
-rw-r--r-- | Examples/test-suite/cpp11_decltype.i | 28 | ||||
-rw-r--r-- | Examples/test-suite/python/cpp11_decltype_runme.py | 8 |
3 files changed, 31 insertions, 6 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 2539a65ba..cd634081c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -624,6 +624,7 @@ CPP11_TEST_CASES += \ cpp11_thread_local \ cpp11_template_double_brackets \ cpp11_template_explicit \ + cpp11_template_parameters_decltype \ cpp11_template_typedefs \ cpp11_type_traits \ cpp11_type_aliasing \ diff --git a/Examples/test-suite/cpp11_decltype.i b/Examples/test-suite/cpp11_decltype.i index deedd5953..ec2772d0c 100644 --- a/Examples/test-suite/cpp11_decltype.i +++ b/Examples/test-suite/cpp11_decltype.i @@ -9,11 +9,35 @@ int i; decltype(i) j; - auto foo( decltype(i) a ) -> decltype(i) { + auto get_number(decltype(i) a) -> decltype(i) { if (a==5) return 10; else return 0; } }; - %} +%} + + +// These are ignored as unable to deduce decltype for (i+j) +%ignore B::k; +%ignore B::get_number_sum; +%ignore B::get_number_address; +#pragma SWIG nowarn=SWIGWARN_CPP11_DECLTYPE + +%inline %{ + class B { + public: + int i; + decltype(i) j; + decltype(i+j) k; + + auto get_number_sum(decltype(i+j) a) -> decltype(i+j) { + return i+j; + } + + auto get_number_address(decltype(&i) a) -> decltype(&i) { + return &i; + } + }; +%} diff --git a/Examples/test-suite/python/cpp11_decltype_runme.py b/Examples/test-suite/python/cpp11_decltype_runme.py index a18f334dc..436443988 100644 --- a/Examples/test-suite/python/cpp11_decltype_runme.py +++ b/Examples/test-suite/python/cpp11_decltype_runme.py @@ -9,10 +9,10 @@ a.j = 10 if a.j != 10: raise RuntimeError("Assignment to a.j failed.") -b = a.foo(5) +b = a.get_int(5) if b != 10: - raise RuntimeError("foo(5) should return 10.") + raise RuntimeError("get_int(5) should return 10.") -b = a.foo(6) +b = a.get_int(6) if b != 0: - raise RuntimeError("foo(6) should return 0.") + raise RuntimeError("get_int(6) should return 0.") |