Fix #686: Add warning for bad line directives#687
Conversation
| ";\n"; | ||
| simplecpp::OutputList outputList; | ||
| makeTokenList(code, dui, &outputList); | ||
| ASSERT_EQUALS("file0,2,portability_line_directive,Line number out of range: 18446744073709551617.\n", |
There was a problem hiding this comment.
I feel that ideally the warning would write the range permitted by the standard. But I am not sure exactly how I want to say it..
Can the warning say that it's UB according to the standard , and write the used standard...
If latest C++ standard is used it would be nice to say that it is conditionally supported instead of UB. However I don't know if the C++ standard allows negative value at all maybe we should say that negative values are unspecified or something..
There was a problem hiding this comment.
Negative values are not even allowed syntactically according to the standard, they should fail to compile due to syntax error.
There was a problem hiding this comment.
My point being that the standard doesn't cover the case of negative numbers, so I think we can ignore them.
|
|
||
| { | ||
| const char code[] = | ||
| "#line 0\n" |
There was a problem hiding this comment.
could we add a negative value test and check what the output is. syntax error or such portability warnings would be fine ... it's not possible to detect such code with cppcheck so I feel we should add this in simplecpp.
There was a problem hiding this comment.
We could output a syntax error and stop processing when the value is negative, that would be the behavior ordained by the standard. What do you think?
There was a problem hiding this comment.
On the other hand, simplecpp is generally pretty lenient when it comes to syntax errors, so it feels weirdly specific to add an error for this. For example, #line 1 garbage here is accepted without error.
There was a problem hiding this comment.
In the current implementation, line directives with negative numbers are silently ignored, which I think is okay. Since the code shouldn't even compile according to the standard, you shouldn't really need cppcheck to find such errors. cppcheck doesn't generally check for syntax errors as far as I'm aware, since they're caught by the compiler.
readfilenow takes aDUIwith information about which standard to use, which is needed to determine if a warning should be issued or not.preprocessnow also includes outputs frommakeTokenListswhich callsreadfile. Some tests had to be fixed to have an ending newline because of this in order to pass.