Skip to content

Conversation

@jefftrull
Copy link
Collaborator

@jefftrull jefftrull commented Jun 24, 2022

The initial part of a conditional block (the if/ifdef/ifndef) takes the "slow" path through the code in cpp_iterator.hpp using the C++ expression grammar, while else and endif directives take the "fast" path. The slow path sets must_emit_line_directive, and it will be cleared after either else or endif is processed. Unfortunately when an else precedes the endif, must_emit_line_directive is cleared and is never set, as only the slow path sets it. The result is proper line directives are issued for the else clause, but not for the subsequent endif.

This change adds setting of must_emit_line_directive in the "fast" path for endif so line directives are considered after an intervening else. It also adds extensive unit tests for line directives.

If merged, this will resolve #24

The initial part of a conditional block (the if/ifdef/ifndef) takes
the "slow" path through the code in cpp_iterator.hpp using the C++
expression grammar, while else and endif directives take the "fast"
path. The slow path sets must_emit_line_directive, and it will be
cleared after either else or endif is processed. Unfortunately when
an else precedes the endif, must_emit_line_directive is cleared and is
never set, as only the slow path sets it. The result is proper line
directives are issued for the else clause, but not for the subsequent
endif.

This changes adds setting of must_emit_line_directive in the "fast"
path for endif so line directives are considered after an intervening else.
@jefftrull jefftrull requested a review from hkaiser June 24, 2022 22:44
Copy link
Collaborator

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Excellent analysis!

@jefftrull jefftrull merged commit 68b8e26 into boostorg:develop Jun 25, 2022
jefftrull added a commit that referenced this pull request Jun 25, 2022
* Fix line directives after endif when else clause is present

The initial part of a conditional block (the if/ifdef/ifndef) takes
the "slow" path through the code in cpp_iterator.hpp using the C++
expression grammar, while else and endif directives take the "fast"
path. The slow path sets must_emit_line_directive, and it will be
cleared after either else or endif is processed. Unfortunately when
an else precedes the endif, must_emit_line_directive is cleared and is
never set, as only the slow path sets it. The result is proper line
directives are issued for the else clause, but not for the subsequent
endif.

This changes adds setting of must_emit_line_directive in the "fast"
path for endif so line directives are considered after an intervening else.
jefftrull added a commit that referenced this pull request Jun 27, 2022
* Fix line directives after endif when else clause is present

The initial part of a conditional block (the if/ifdef/ifndef) takes
the "slow" path through the code in cpp_iterator.hpp using the C++
expression grammar, while else and endif directives take the "fast"
path. The slow path sets must_emit_line_directive, and it will be
cleared after either else or endif is processed. Unfortunately when
an else precedes the endif, must_emit_line_directive is cleared and is
never set, as only the slow path sets it. The result is proper line
directives are issued for the else clause, but not for the subsequent
endif.

This changes adds setting of must_emit_line_directive in the "fast"
path for endif so line directives are considered after an intervening else.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Line numbers wrong after conditional section

2 participants