diff --git a/src/Generator/Passes/CheckStaticClass.cs b/src/Generator/Passes/CheckStaticClass.cs index 359ba056..ddafc25a 100644 --- a/src/Generator/Passes/CheckStaticClass.cs +++ b/src/Generator/Passes/CheckStaticClass.cs @@ -90,8 +90,8 @@ namespace CppSharp.Passes // If one exists, we assume it's a factory function and the class is // not meant to be static. It's a simple heuristic but it should be // good enough for the time being. - if (@class.Functions.Any(ReturnsClassInstance) || - @class.Methods.Any(ReturnsClassInstance)) + if (@class.Functions.Any(m => !m.IsOperator && ReturnsClassInstance(m)) || + @class.Methods.Any(m => !m.IsOperator && ReturnsClassInstance(m))) return false; // If the class is to be used as an opaque type, then it cannot be diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 06f2a00c..094f818e 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -342,6 +342,9 @@ public class CommonTests : GeneratorTestFixture [Test] public void TestStaticClasses() { + Type staticClassType = typeof(TestStaticClass); + // Only static class can be both abstract and sealed + Assert.IsTrue(staticClassType.IsAbstract && staticClassType.IsSealed); Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3)); Assert.That(TestStaticClass.OneTwoThree, Is.EqualTo(123)); Assert.That(TestStaticClassDerived.Foo, Is.EqualTo(0)); diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 02657bce..4bf3849d 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -673,3 +673,8 @@ void hasPointerParam(const Foo& foo) void sMallFollowedByCapital() { } + +TestStaticClass& TestStaticClass::operator=(const TestStaticClass& oth) +{ + return *this; +} diff --git a/tests/Common/Common.h b/tests/Common/Common.h index bf50f333..0cb7a66d 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -388,13 +388,14 @@ struct DLL_API TestStaticClass static int GetOneTwoThree(); -protected: + TestStaticClass& operator=(const TestStaticClass& oth); + +private: static int _Mult(int a, int b); static int GetFourFiveSix(); -private: TestStaticClass(); };