Skip to content

Fix ICE when comment on last line on global object, closes #344 #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,15 @@ class positional_printer
//-----------------------------------------------------------------------
// Finalize
//
auto finalize()
auto finalize(phases phase = phases::phase2_func_defs)
{
flush_comments( {curr_pos.lineno+1, 1} );

if (
is_open()
&& psource
&& psource->has_cpp2()
&& phase == phases::phase2_func_defs
)
{
// Always make sure the last line ends with a newline
Expand Down Expand Up @@ -1286,6 +1287,20 @@ class cppfront
++curr_lineno;
}

if (
printer.get_phase() == positional_printer::phase1_type_defs_func_decls
) {
const auto& comments = tokens.get_comments();
// check if there is any comment left that should be printed in phase1
if (
std::any_of(std::cbegin(comments), std::cend(comments), [this](const auto& c){
return !c.dbg_was_printed && !parser.is_within_function_body(c.start.lineno);
})
) {
printer.finalize(positional_printer::phase1_type_defs_func_decls);
}
}

// We can stop here if there's no Cpp2 code -- a file with no Cpp2
// should have perfect passthrough verifiable with diff, including
// that we didn't misidentify anything as Cpp2 (even in the
Expand Down