[PATCH] D12359: New warning -Wnonconst-parameter when a pointer parameter can be const
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 17:17:03 PST 2015
On Wed, Nov 11, 2015 at 10:11 PM, Daniel Marjamäki <
daniel.marjamaki at evidente.se> wrote:
> danielmarjamaki added a comment.
>
> In http://reviews.llvm.org/D12359#287522, @rsmith wrote:
>
> > Why does this construct justify the compiler emitting a warning? It
> seems to be reporting a fact about the code rather than a bug, and as there
> are many coding styles where variables are not routinely marked as const
> whenever possible, this appears to be checking that the code conforms to a
> particular coding style. As such, this seems like a better fit as a
> clang-tidy check than as a compiler warning.
>
I don't think you've responded to this. Why do you think this situation
justifies the compiler emitting a warning? This seems outside the normal
scope of things that we'd warn on, since we have no proof or strong
evidence that the code is buggy or does something other than what the
author intended. There are lots of legitimate scenarios when a function
might be passed a non-const pointer where it has no intention of modifying
the pointee (perhaps the function is a callback or similar and must have a
certain signature), and there seems to be no obvious syntactic way to
suppress this warning on a case-by-case basis.
Conversely, this seems very well suited to exist as a clang-tidy check.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151112/6198f713/attachment.html>
More information about the cfe-commits
mailing list