diff --git a/cxxheaderparser/parser.py b/cxxheaderparser/parser.py index 8a51e81..45f7fb6 100644 --- a/cxxheaderparser/parser.py +++ b/cxxheaderparser/parser.py @@ -719,11 +719,7 @@ def _parse_template_specialization(self) -> TemplateSpecialization: args.append(TemplateArgument(dtype, param_pack)) else: # special case for sizeof...(thing) - if ( - param_pack - and len(val.tokens) == 1 - and val.tokens[0].value == "sizeof" - ): + if param_pack and val.tokens[-1].value == "sizeof": val.tokens.append(Token("...", "ELLIPSIS")) tok = self._next_token_must_be("(") raw_toks = self._consume_balanced_tokens(tok) diff --git a/tests/test_template.py b/tests/test_template.py index cee092d..2a13b66 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -2352,3 +2352,68 @@ def test_sizeof_pack() -> None: ] ) ) + + +def test_deduction_sizeof_pack() -> None: + content = """ + template + SwerveDriveKinematics(ModuleTranslation, ModuleTranslations...) + -> SwerveDriveKinematics<1 + sizeof...(ModuleTranslations)>; + """ + data = parse_string(content, cleandoc=True) + + assert data == ParsedData( + namespace=NamespaceScope( + deduction_guides=[ + DeductionGuide( + result_type=Type( + typename=PQName( + segments=[ + NameSpecifier( + name="SwerveDriveKinematics", + specialization=TemplateSpecialization( + args=[ + TemplateArgument( + arg=Value( + tokens=[ + Token(value="1"), + Token(value="+"), + Token(value="sizeof"), + Token(value="..."), + Token(value="("), + Token( + value="ModuleTranslations" + ), + Token(value=")"), + ] + ), + param_pack=True, + ) + ] + ), + ) + ] + ) + ), + name=PQName(segments=[NameSpecifier(name="SwerveDriveKinematics")]), + parameters=[ + Parameter( + type=Type( + typename=PQName( + segments=[NameSpecifier(name="ModuleTranslation")] + ) + ) + ), + Parameter( + type=Type( + typename=PQName( + segments=[NameSpecifier(name="ModuleTranslations")] + ) + ), + param_pack=True, + ), + ], + ) + ] + ) + )