summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2023-03-08 19:43:26 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2023-03-08 19:45:17 +0000
commit4a6f6283aa7e0b15427c60988b0940dc0349f14a (patch)
tree2279eda71872407229b5dd1c3776dc6507187489 /Source
parenta92871d9d12f4aa8e82640f157bb7ffdbf138169 (diff)
downloadswig-4a6f6283aa7e0b15427c60988b0940dc0349f14a.tar.gz
Fix duplicate const in generated code wrapping templates
Fix duplicate const in generated code when template instantiation type is const and use of template parameter is also explicitly const, such as: template <typename T> struct Conster { void cccc1(T const& t) {} }; %template(ConsterInt) Conster<const int>; Above previously led to generated code: (arg1)->cccc1((int const const &)*arg2); instead of (arg1)->cccc1((int const &)*arg2);
Diffstat (limited to 'Source')
-rw-r--r--Source/Swig/stype.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c
index e9cbf7b43..7a7b727a2 100644
--- a/Source/Swig/stype.c
+++ b/Source/Swig/stype.c
@@ -1275,6 +1275,11 @@ String *SwigType_manglestr(const SwigType *s) {
* SwigType_typename_replace()
*
* Replaces a typename in a type with something else. Needed for templates.
+ * Collapses duplicate const into a single const.
+ * Reference collapsing probably should be implemented here.
+ * Example:
+ * t=r.q(const).T pat=T rep=int => r.q(const).int
+ * t=r.q(const).T pat=T rep=q(const).int => r.q(const).int (duplicate const removed)
* ----------------------------------------------------------------------------- */
void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
@@ -1297,7 +1302,15 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
if (SwigType_issimple(e)) {
if (Equal(e, pat)) {
/* Replaces a type of the form 'pat' with 'rep<args>' */
- Replace(e, pat, rep, DOH_REPLACE_ANY);
+ if (SwigType_isconst(rep) && i > 0 && SwigType_isconst(Getitem(elem, i - 1))) {
+ /* Collapse duplicate const into a single const */
+ SwigType *rep_without_const = Copy(rep);
+ Delete(SwigType_pop(rep_without_const));
+ Replace(e, pat, rep_without_const, DOH_REPLACE_ANY);
+ Delete(rep_without_const);
+ } else {
+ Replace(e, pat, rep, DOH_REPLACE_ANY);
+ }
} else if (SwigType_istemplate(e)) {
/* Replaces a type of the form 'pat<args>' with 'rep' */
{