diff --git a/cxxheaderparser/parser.py b/cxxheaderparser/parser.py index ff0f04b..ed5a99a 100644 --- a/cxxheaderparser/parser.py +++ b/cxxheaderparser/parser.py @@ -2307,6 +2307,9 @@ def _parse_operator_conversion( cmods.validate(var_ok=False, meth_ok=False, msg="parsing conversion operator") + # Check for any cv decorations for the type + rtype = self._parse_cv_ptr(ctype) + # then this must be a method self._next_token_must_be("(") @@ -2317,7 +2320,7 @@ def _parse_operator_conversion( if self._parse_function( mods, - ctype, + rtype, pqname, op, template, diff --git a/tests/test_operators.py b/tests/test_operators.py index 8d3bb60..709e11b 100644 --- a/tests/test_operators.py +++ b/tests/test_operators.py @@ -3,8 +3,10 @@ from cxxheaderparser.types import ( ClassDecl, FundamentalSpecifier, + MoveReference, NameSpecifier, Operator, + Pointer, PQName, Parameter, Reference, @@ -617,3 +619,75 @@ class Foo ] ) ) + + +def test_conversion_operators_decorated() -> None: + content = """ + struct S { + operator const native_handle_t*() const; + operator const native_handle_t&() const; + operator const native_handle_t&&() const; + }; + """ + data = parse_string(content, cleandoc=True) + + assert data == ParsedData( + namespace=NamespaceScope( + classes=[ + ClassScope( + class_decl=ClassDecl( + typename=PQName( + segments=[NameSpecifier(name="S")], classkey="struct" + ) + ), + methods=[ + Operator( + return_type=Pointer( + ptr_to=Type( + typename=PQName( + segments=[NameSpecifier(name="native_handle_t")] + ), + const=True, + ) + ), + name=PQName(segments=[NameSpecifier(name="operator")]), + parameters=[], + access="public", + const=True, + operator="conversion", + ), + Operator( + return_type=Reference( + ref_to=Type( + typename=PQName( + segments=[NameSpecifier(name="native_handle_t")] + ), + const=True, + ) + ), + name=PQName(segments=[NameSpecifier(name="operator")]), + parameters=[], + access="public", + const=True, + operator="conversion", + ), + Operator( + return_type=MoveReference( + moveref_to=Type( + typename=PQName( + segments=[NameSpecifier(name="native_handle_t")] + ), + const=True, + ) + ), + name=PQName(segments=[NameSpecifier(name="operator")]), + parameters=[], + access="public", + const=True, + operator="conversion", + ), + ], + ) + ] + ) + )