Skip to content

Commit 6e0baed

Browse files
committed
Translate operator overloads with simple conditions
1 parent 33f325f commit 6e0baed

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/cppconv/dwriter/declarationcode.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,10 @@ void declarationToDCode(ref CodeWriter code, DWriterData data, Declaration d, im
13421342
return;
13431343
}
13441344
string op = d.name["operator ".length .. $];
1345-
if (d.type2.kind == TypeKind.function_)
1345+
QualType type2 = filterType(d.type2, condition, semantic);
1346+
if (type2.kind == TypeKind.function_)
13461347
{
1347-
auto functionType = cast(FunctionType) d.type2.type;
1348+
auto functionType = cast(FunctionType) type2.type;
13481349
if (op.among("++", "--", "*", "+", "-", "~")
13491350
&& functionType.parameters.length == 0 && parentClassTree.isValid)
13501351
{

tests/single/test390.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ void f()
6969
a <<= b;
7070
a >>= b;
7171
}
72+
73+
#ifndef DEF
74+
struct S2
75+
{
76+
S2 operator +(S2 rhs) { return S2(); }
77+
};
78+
#endif

tests/single/test390.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ void f()
7777
a >>= b;
7878
}
7979

80+
static if (!defined!"DEF")
81+
{
82+
struct S2
83+
{
84+
S2 opBinary(string op)(S2 rhs) if (op == "+") { return S2(); }
85+
}
86+
}
87+

0 commit comments

Comments
 (0)