AutosarC++17_03-A2.8.1ΒΆ

The character shall not occur as a last character of a C++ comment

Required inputs: IR

Line-splicing via backslash-newline in C++ comments is confusing because it makes the comment extend to the next line, which is not immediately obvious from reading the code. This can lead to unexpected behavior where code following the comment is treated as part of the comment. Additionally, line-splicing in comments is rarely intentional and usually indicates a mistake.
Bad code (line splicing in comment):
// This is a comment that continues \
int x = 5;  // Error: This becomes part of the comment due to line-splicing!
Good code (proper multi-line comment):
// This is a comment that continues
// to the next line with a fresh comment
int x = 5;  // OK: properly formed
Good code (using block comment):
/* This is a multi-line comment
   that spans multiple lines cleanly
   without confusion */
int x = 5;  // OK: clear and unambiguous

Possible Messages

Key

Text

Severity

Disabled

line_splicing_in_cpp_comment

Line-splicing shall not be used in // comments.

None

False

Options