[PATCH] [clang-tidy] Add a checker for swapped literal arguments.

David Blaikie dblaikie at gmail.com
Thu Jul 10 08:35:52 PDT 2014


Worth a compiler warning?

If we're talking literals, could we just warn whenever someone wrote a
literal with a mismatched parameter? (3.0 for an int parameter -
skipping 3e6 as being safe because people like to write big ints with
exponent notation even though it's actually a double)

Things like passing literal true/false for int parameters is also
often a bad sign... (I tried to implement bool literal conversion at
some point, but never got around to finishing it - it caught some
cases like this)

On Thu, Jul 10, 2014 at 2:56 AM, Benjamin Kramer <benny.kra at gmail.com> wrote:
> Hi alexfh, djasper,
>
> This looks for swapped arguments by looking at implicit conversions of
> literal arguments
>
> void Foo(int, double);
> Foo(1.0, 3);  // Most likely a bug
>
> We do this by checking that the same argument types exist in literals and
> the declaration of the function.
>
> http://reviews.llvm.org/D4457
>
> Files:
>   clang-tidy/misc/CMakeLists.txt
>   clang-tidy/misc/ImplicitArgumentConversion.cpp
>   clang-tidy/misc/ImplicitArgumentConversion.h
>   clang-tidy/misc/MiscTidyModule.cpp
>   test/clang-tidy/misc-implicit-argument-conversion.cpp
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list