[Bug c++/59653] New: warn when non-const parameter or local variable is not modified

mw_triad at users dot sourceforge.net gcc-bugzilla@gcc.gnu.org
Tue Dec 31 19:21:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59653

            Bug ID: 59653
           Summary: warn when non-const parameter or local variable is not
                    modified
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mw_triad at users dot sourceforge.net

Some coding styles specify that local variables that are not modified should be
marked 'const' in order (in theory) to allow for compiler optimization. It
would be great if gcc could omit a warning for violations of this rule.

I imagine this would work by setting a flag on a non-const local variable
instantiation that is cleared when the variable is used in a manner that
requires that is not be 'const'. If the flag is not cleared when the variable
goes out of scope (which presumably gcc knows, as it needs to invoke the dtor
at this time if the type has one), a warning would be emitted.

The same for function/method parameters, but likely as a separate warning,
would also be desirable.

Closely related to bug #59552; that one should probably be a different option,
but the implementation is likely similar.



More information about the Gcc-bugs mailing list