8000 Fix =default constructor/destructor detection · robotpy/robotpy-cppheaderparser@694536e · GitHub
[go: up one dir, main page]

Skip to content

Commit 694536e

Browse files
committed
Fix =default constructor/destructor detection
... apparently the unit tests were totally broken, go figure
1 parent 4ecb8a4 commit 694536e

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,9 @@ def parse_method_type(self, stack):
22332233
info["pure_virtual"] = True
22342234
elif stack[-2] == "delete":
22352235
info["deleted"] = True
2236+
elif stack[-2] == "default":
2237+
info["default"] = True
2238+
info["defined"] = True
22362239

22372240
r = header.split()
22382241
name = None
@@ -2274,15 +2277,9 @@ def parse_method_type(self, stack):
22742277

22752278
if name.startswith("~"):
22762279
info["destructor"] = True
2277-
if "default;" in stack:
2278-
info["defined"] = True
2279-
info["default"] = True
22802280
name = name[1:]
22812281
elif not a or (name == self.curClass and len(self.curClass)):
22822282
info["constructor"] = True
2283-
if "default;" in stack:
2284-
info["defined"] = True
2285-
info["default"] = True
22862283

22872284
info["name"] = name
22882285

test/TestSampleClass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,13 @@ int non_vararg_func(int foo, const char* fmt);
780780
class DefaultConstDest {
781781
public:
782782
DefaultConstDest() =default ; // spacing check
783-
DefaultConstDest() = default ; // spacing check
783+
~DefaultConstDest() = default ; // spacing check
784784
};
785785
// default constructor on a class containing "default" as name (edge case check)
786786
class default_class_tricky {
787787
public:
788788
default_class_tricky();
789-
default_class_tricky();
789+
~default_class_tricky();
790790

791791
void randomMethod1_default();
792792
void defaultrandomMethod2();

test/test_CppHeaderParser.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,7 @@ def test_Grackle_const_noexcept_noexcept_operator(self):
26482648

26492649

26502650
# Test enhancement 13 (default constructor / destructor)
2651-
class DefaultConstDest_TestCase:
2651+
class DefaultConstDest_TestCase(unittest.TestCase):
26522652
def setUp(self):
26532653
self.cppHeader = CppHeaderParser.CppHeader("TestSampleClass.h")
26542654

@@ -3807,6 +3807,24 @@ def test_fn(self):
38073807
self.assertEqual(props[1]["name"], "y")
38083808

38093809

3810+
class Default_TestCase(unittest.TestCase):
3811+
def setUp(self):
3812+
self.cppHeader = CppHeaderParser.CppHeader(
3813+
"""
3814+
class A {
3815+
public:
3816+
A() = default;
3817+
};
3818+
""",
3819+
"string",
3820+
)
3821+
3822+
def test_fn(self):
3823+
m = self.cppHeader.classes["A"]["methods"]["public"][0]
3824+
self.assertEqual(m["constructor"], True)
3825+
self.assertEqual(m["default"], True)
3826+
3827+
38103828
class Deleted_TestCase(unittest.TestCase):
38113829
def setUp(self):
38123830
self.cppHeader = CppHeaderParser.CppHeader(

0 commit comments

Comments
 (0)
0