Skip to content

Commit a08e24b

Browse files
committed
Generate valid C# for implicit conversion to const char*
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 5a92220 commit a08e24b

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,6 @@ public void GenerateFunctionCall(string functionName, List<Parameter> parameters
29012901
ArgName = Helpers.ReturnIdentifier,
29022902
ReturnVarName = Helpers.ReturnIdentifier,
29032903
ReturnType = returnType,
2904-
Parameter = operatorParam,
29052904
Function = function
29062905
};
29072906

tests/CSharp/CSharp.Tests.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void TestDefaultArguments()
248248
methodsWithDefaultValues.DefaultEmptyEnum();
249249
methodsWithDefaultValues.DefaultRefTypeBeforeOthers();
250250
methodsWithDefaultValues.DefaultRefTypeAfterOthers();
251-
methodsWithDefaultValues.DefaultRefTypeBeforeAndAfterOthers(0, null);
251+
methodsWithDefaultValues.DefaultRefTypeBeforeAndAfterOthers();
252252
methodsWithDefaultValues.DefaultIntAssignedAnEnum();
253253
methodsWithDefaultValues.defaultRefAssignedValue();
254254
methodsWithDefaultValues.DefaultRefAssignedValue();
@@ -1276,7 +1276,17 @@ public void TestConstCharStarRef()
12761276
}
12771277

12781278
[Test]
1279-
public void Test()
1279+
public void TestImplicitConversionToString()
1280+
{
1281+
using (Foo foo = new Foo("name"))
1282+
{
1283+
string name = foo;
1284+
Assert.That(name, Is.EqualTo("name"));
1285+
}
1286+
}
1287+
1288+
[Test]
1289+
public void TestHasFunctionPointerField()
12801290
{
12811291
using (var hasFunctionPtrField = new HasFunctionPtrField())
12821292
{

tests/CSharp/CSharp.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ Foo::Foo(const QString& name)
88

99
Foo::Foo(const char* name) : publicFieldMappedToEnum(TestFlag::Flag2)
1010
{
11+
if (name)
12+
{
13+
_name = name;
14+
}
1115
A = 10;
1216
P = 50;
1317
}
1418

19+
Foo::Foo(const Foo& other) : A(other.A), P(other.P),
20+
templateInAnotherUnit(other.templateInAnotherUnit),
21+
_name(other._name)
22+
{
23+
}
24+
1525
Foo::Foo(int a, int p) : publicFieldMappedToEnum(TestFlag::Flag2)
1626
{
1727
A = a;
@@ -26,6 +36,10 @@ Foo::Foo(wchar_t ch)
2636
{
2737
}
2838

39+
Foo::~Foo()
40+
{
41+
}
42+
2943
int Foo::method()
3044
{
3145
return 1;
@@ -104,6 +118,11 @@ int Foo::operator --()
104118
return 4;
105119
}
106120

121+
Foo::operator const char*() const
122+
{
123+
return _name.data();
124+
}
125+
107126
const Foo& Bar::operator[](int i) const
108127
{
109128
return m_foo;
@@ -215,6 +234,10 @@ Bar::Bar(Items item)
215234
{
216235
}
217236

237+
Bar::~Bar()
238+
{
239+
}
240+
218241
int Bar::method()
219242
{
220243
return 2;
@@ -263,10 +286,18 @@ ForceCreationOfInterface::ForceCreationOfInterface()
263286
{
264287
}
265288

289+
ForceCreationOfInterface::~ForceCreationOfInterface()
290+
{
291+
}
292+
266293
Baz::Baz(Bar::Items item)
267294
{
268295
}
269296

297+
Baz::~Baz()
298+
{
299+
}
300+
270301
int Baz::takesQux(const Qux& qux)
271302
{
272303
return qux.farAwayFunc();
@@ -974,6 +1005,10 @@ InheritsProtectedVirtualFromSecondaryBase::InheritsProtectedVirtualFromSecondary
9741005
{
9751006
}
9761007

1008+
InheritsProtectedVirtualFromSecondaryBase::~InheritsProtectedVirtualFromSecondaryBase()
1009+
{
1010+
}
1011+
9771012
void InheritsProtectedVirtualFromSecondaryBase::protectedVirtual()
9781013
{
9791014
}

tests/CSharp/CSharp.h

+8
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class DLL_API Foo
1313
public:
1414
Foo(const QString& name);
1515
Foo(const char* name = 0);
16+
Foo(const Foo& other);
1617
Foo(int a, int p = 0);
1718
Foo(char16_t ch);
1819
Foo(wchar_t ch);
20+
~Foo();
1921
int method();
2022
int operator[](int i) const;
2123
int operator[](unsigned int i);
@@ -38,13 +40,15 @@ class DLL_API Foo
3840

3941
int operator ++();
4042
int operator --();
43+
operator const char*() const;
4144

4245
bool btest[5];
4346
QFlags<TestFlag> publicFieldMappedToEnum;
4447

4548
protected:
4649
int P;
4750
TemplateInAnotherUnit<int> templateInAnotherUnit;
51+
std::string _name;
4852
};
4953

5054
class DLL_API Quux
@@ -93,6 +97,7 @@ class DLL_API Bar : public Qux
9397
Bar();
9498
Bar(Qux qux);
9599
Bar(Items item);
100+
~Bar();
96101
int method();
97102
const Foo& operator[](int i) const;
98103
Foo& operator[](int i);
@@ -121,6 +126,7 @@ class DLL_API ForceCreationOfInterface : public Foo, public Bar
121126
{
122127
public:
123128
ForceCreationOfInterface();
129+
~ForceCreationOfInterface();
124130
};
125131

126132
class DLL_API Baz : public Foo, public Bar
@@ -136,6 +142,7 @@ class DLL_API Baz : public Foo, public Bar
136142

137143
Baz();
138144
Baz(Bar::Items item);
145+
~Baz();
139146

140147
int P;
141148

@@ -734,6 +741,7 @@ class DLL_API InheritsProtectedVirtualFromSecondaryBase : public InheritanceBuff
734741
{
735742
public:
736743
InheritsProtectedVirtualFromSecondaryBase();
744+
~InheritsProtectedVirtualFromSecondaryBase();
737745
protected:
738746
void protectedVirtual();
739747
};

0 commit comments

Comments
 (0)