Conversation
There was a problem hiding this comment.
Pull request overview
Prevents sg.pl from crashing on explicit template specializations (template <>) by detecting the empty parameter list case and skipping parsing of the specialization body.
Changes:
- Return an empty parameter list from
template_args()when encounteringtemplate <>. - In
parse_template(), detect explicit specializations and skip the entire declaration/body so they don’t generate.boutputs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| my @tmp; | ||
| expect_next("<"); | ||
| if(next_is(">")) | ||
| { |
There was a problem hiding this comment.
template_args() relies on next_is(\">\") consuming the token; if next_is is implemented as a pure lookahead in this parser, the > will remain in the stream and the subsequent parsing will desync. Consider replacing this with an explicit consume (e.g., expect_next(\">\") or a dedicated consume function) before returning the empty list, so the behavior doesn’t depend on next_is side-effects.
| { | |
| { | |
| # Empty template parameter list: consume '>' explicitly so parsing stays in sync | |
| expect_next(">"); |
| consume_block('{','}'); | ||
| next_is(";"); |
There was a problem hiding this comment.
The semicolon handling after consume_block is currently implicit and ignores the return value of next_is(\";\"). If the goal is to optionally consume a trailing ;, consider using a function/name that’s explicitly "consume if present" (or check the return value), to avoid depending on undocumented next_is behavior and to make the intent clearer.
sg.pl crashes when a header contains an explicit template specialization (template <>) because template_args() expects class/bool/int after '<' but gets '>'. Return an empty parameter list from template_args() on 'template <>' and skip the entire specialization in parse_template(), since explicit specializations are not new class definitions and should not generate .b files. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Hi @Ozaq could you please provide a test that was previously crashing? |
|
If I understood correctly, the issue occurs when the file contains something like: which ends with the failure Assuming this is indeed the problem the issue is fixed! But this certainly deserves a test to ensure the use case is handled properly |
marcosbento
left a comment
There was a problem hiding this comment.
Please add a test to cover the failure test that triggered these changes.
| # granted to it by virtue of its status as an intergovernmental organisation nor | ||
| # does it submit to any jurisdiction. | ||
|
|
||
| # ========================================================================== |
There was a problem hiding this comment.
Thank you for adding this description. It is very useful!
| grep { length($_); } # drop empty tokens | ||
| map { /\W/ ? split('',$_) : $_; } # split non-word tokens into chars | ||
| map { s/\s//g; $_; } # strip whitespace within tokens | ||
| split(/\b/, $x ); # split on word boundaries |
There was a problem hiding this comment.
nit: please align the # "column"
Description
sg.pl crashes when a header contains an explicit template specialization (template <>) because template_args() expects class/bool/int after '<' but gets '>'.
Return an empty parameter list from template_args() on 'template <>' and skip the entire specialization in parse_template(), since explicit specializations are not new class definitions and should not generate .b files.
Contributor Declaration
By opening this pull request, I affirm the following: