One-line comments should not have forced continuation

# T001

# One-line comments should not have forced continuation

Description:

The one-line comment is a comment that starts with `//`.

The usual intent is to let the comment continue till the end of the line, but the preprocessing rules of the language allow to actually continue the comment in the next line if line-splicing is forced with the backslash at the end of the line:

    void foo()
    {
        // this comment is continued in the next line \
        exit(0);
    }

It is not immediately obvious what happens in this example. Moreover, the line-splicing works only if the backslash is really the last character in the line - which is error prone because any white characters that might appear after the backslash will change the meaning of the program without being visible in the code.

Compliance: Inspirel

Show source code for this rule

Hide source code

    # One-line comments should not have forced continuation

    foreach f [getSourceFileNames] {
        foreach t [getTokens $f 1 0 -1 -1 {cppcomment}] {
            set lineNumber [lindex $t 1]
            set wholeLine [getLine $f $lineNumber]

            if {[string index $wholeLine end] == "\\"} {
                report $f $lineNumber "line-continuation in one-line comment"
            }
        }
    }

Rule index