From 476e9894975e8d1da2ecf23f36ca22738e86386e Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sat, 28 Sep 2024 19:05:44 -0400 Subject: [PATCH] Any function can be deleted, support that - Fixes #105 --- cxxheaderparser/parser.py | 5 +++++ cxxheaderparser/types.py | 2 +- tests/test_fn.py | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cxxheaderparser/parser.py b/cxxheaderparser/parser.py index d633e2a..8a51e81 100644 --- a/cxxheaderparser/parser.py +++ b/cxxheaderparser/parser.py @@ -1937,6 +1937,11 @@ def _parse_fn_end(self, fn: Function) -> None: if self.lex.token_if("{"): self._discard_contents("{", "}") fn.has_body = True + elif self.lex.token_if("="): + if self.lex.token_if_val("delete"): + fn.deleted = True + else: + raise self._parse_error(None, "expected 'delete") def _parse_method_end(self, method: Method) -> None: """ diff --git a/cxxheaderparser/types.py b/cxxheaderparser/types.py index 59169fc..ea768b6 100644 --- a/cxxheaderparser/types.py +++ b/cxxheaderparser/types.py @@ -696,6 +696,7 @@ class Function: extern: typing.Union[bool, str] = False static: bool = False inline: bool = False + deleted: bool = False #: If true, the body of the function is present has_body: bool = False @@ -764,7 +765,6 @@ class Method(Function): constructor: bool = False explicit: bool = False default: bool = False - deleted: bool = False destructor: bool = False diff --git a/tests/test_fn.py b/tests/test_fn.py index 4f67a41..34734d6 100644 --- a/tests/test_fn.py +++ b/tests/test_fn.py @@ -1313,3 +1313,25 @@ def test_msvc_inline() -> None: ] ) ) + + +def test_deleted_function() -> None: + content = """ + void trim() = delete; + """ + data = parse_string(content, cleandoc=True) + + assert data == ParsedData( + namespace=NamespaceScope( + functions=[ + Function( + return_type=Type( + typename=PQName(segments=[FundamentalSpecifier(name="void")]) + ), + name=PQName(segments=[NameSpecifier(name="trim")]), + parameters=[], + deleted=True, + ) + ] + ) + )