[PATCH] D12359: New warning -Wnonconst-parameter when a pointer parameter can be const

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 11 14:14:15 PST 2015


rsmith added a comment.

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.

The choice to only apply this check to pointer parameters to functions seems arbitrary. What is the motivation for that?


================
Comment at: include/clang/AST/Decl.h:854
@@ +853,3 @@
+  /// \brief Whether this variable has non-const use so it can't be const.
+  unsigned NonConstUse:1;
+
----------------
This is not OK; it'll make all `VarDecl`s 8 bytes larger on 64-bit systems.


http://reviews.llvm.org/D12359





More information about the cfe-commits mailing list