Skip to content

Commit c914b1e

Browse files
committed
Merge branch 'abstract-conversion-operators'
* abstract-conversion-operators: Add test cases for abstract user-defined conversion operators Recognize C++ conversion operators with trailing '= 0' as abstract
2 parents 6cec69e + eb2be58 commit c914b1e

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Examples/test-suite/common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ CPP_TEST_CASES += \
184184
director_classes \
185185
director_classic \
186186
director_constructor \
187+
director_conversion_operators \
187188
director_default \
188189
director_detect \
189190
director_enum \
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
%module(directors="1") director_conversion_operators
2+
3+
%feature("director");
4+
5+
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Bar;
6+
7+
%rename(toFoo) Bar::operator Foo();
8+
%rename(toFooPtr) Bar::operator Foo *();
9+
%rename(toFooRef) Bar::operator Foo &();
10+
%rename(toFooPtrRef) Bar::operator Foo *&();
11+
12+
%rename(toOtherFoo) Bar::operator OtherFoo();
13+
%rename(toOtherFooPtr) Bar::operator OtherFoo *();
14+
%rename(toOtherFooRef) Bar::operator OtherFoo &();
15+
%rename(toOtherFooPtrRef) Bar::operator OtherFoo *&();
16+
17+
%inline %{
18+
struct Foo {
19+
};
20+
struct OtherFoo {
21+
};
22+
struct Bar {
23+
Foo myFoo;
24+
Foo *myFooPtr;
25+
virtual ~Bar() { }
26+
virtual operator Foo () { return Foo(); }
27+
virtual operator Foo *() { return &myFoo; }
28+
virtual operator Foo &() { return myFoo; }
29+
virtual operator Foo *&() { return myFooPtr; }
30+
virtual operator OtherFoo () = 0;
31+
virtual operator OtherFoo *() = 0;
32+
virtual operator OtherFoo &() = 0;
33+
virtual operator OtherFoo *&() = 0;
34+
};
35+
%}

Source/CParse/parser.y

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4800,6 +4800,9 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
48004800
if ($8.qualifier) {
48014801
SwigType_push($4,$8.qualifier);
48024802
}
4803+
if ($8.val) {
4804+
Setattr($$,"value",$8.val);
4805+
}
48034806
Setattr($$,"refqualifier",$8.refqualifier);
48044807
Setattr($$,"decl",$4);
48054808
Setattr($$,"parms",$6);
@@ -4818,6 +4821,9 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
48184821
if ($8.qualifier) {
48194822
SwigType_push(decl,$8.qualifier);
48204823
}
4824+
if ($8.val) {
4825+
Setattr($$,"value",$8.val);
4826+
}
48214827
Setattr($$,"refqualifier",$8.refqualifier);
48224828
Setattr($$,"decl",decl);
48234829
Setattr($$,"parms",$6);
@@ -4836,6 +4842,9 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
48364842
if ($8.qualifier) {
48374843
SwigType_push(decl,$8.qualifier);
48384844
}
4845+
if ($8.val) {
4846+
Setattr($$,"value",$8.val);
4847+
}
48394848
Setattr($$,"refqualifier",$8.refqualifier);
48404849
Setattr($$,"decl",decl);
48414850
Setattr($$,"parms",$6);
@@ -4856,6 +4865,9 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
48564865
if ($9.qualifier) {
48574866
SwigType_push(decl,$9.qualifier);
48584867
}
4868+
if ($9.val) {
4869+
Setattr($$,"value",$9.val);
4870+
}
48594871
Setattr($$,"refqualifier",$9.refqualifier);
48604872
Setattr($$,"decl",decl);
48614873
Setattr($$,"parms",$7);
@@ -4873,7 +4885,10 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
48734885
if ($7.qualifier) {
48744886
SwigType_push(t,$7.qualifier);
48754887
}
4876-
Setattr($$,"refqualifier",$7.refqualifier);
4888+
if ($7.val) {
4889+
Setattr($$,"value",$7.val);
4890+
}
4891+
Setattr($$,"refqualifier",$7.refqualifier);
48774892
Setattr($$,"decl",t);
48784893
Setattr($$,"parms",$5);
48794894
Setattr($$,"conversion_operator","1");

0 commit comments

Comments
 (0)