Skip to content

Fix #686: Add warning for bad line directives#687

Open
glankk wants to merge 18 commits into
cppcheck-opensource:masterfrom
glankk:686
Open

Fix #686: Add warning for bad line directives#687
glankk wants to merge 18 commits into
cppcheck-opensource:masterfrom
glankk:686

Conversation

@glankk

@glankk glankk commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

readfile now takes a DUI with information about which standard to use, which is needed to determine if a warning should be issued or not. preprocess now also includes outputs from makeTokenLists which calls readfile. Some tests had to be fixed to have an ending newline because of this in order to pass.

Comment thread test.cpp Outdated
Comment thread test.cpp
Comment thread simplecpp.cpp Outdated
Comment thread simplecpp.cpp Outdated
Comment thread simplecpp.cpp Outdated
Comment thread simplecpp.cpp Outdated
glankk and others added 2 commits July 23, 2026 11:42
Co-authored-by: Daniel Marjamäki <daniel.marjamaki@gmail.com>
Comment thread simplecpp.cpp Outdated
glankk and others added 2 commits July 23, 2026 13:24
Co-authored-by: Daniel Marjamäki <daniel.marjamaki@gmail.com>
Comment thread simplecpp.cpp Outdated
Comment thread simplecpp.cpp
try {
line = std::stoul(ppTok->str());
} catch (...) {
line = std::numeric_limits<unsigned long>::max();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this value might not work well.. it means tokens might get line number 0 which cppcheck interprets as "no line".

I suggest that the value passed in the lineDirective call will be 1. After reporting the error message.. change it to 1?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

or assign maxvalue+1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually it might be better that we just ignore the line number and use the current one when it's out of range, what do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Or just discard the line directive entirely.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would be fine with both those options.

Comment thread test.cpp
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.

2 participants