[clang-tidy] Extend 'bugprone-easily-swappable-parameters' with optionally considerin...
authorWhisperity <whisperity@gmail.com>
Wed, 20 Nov 2019 13:12:57 +0000 (14:12 +0100)
committerWhisperity <whisperity@gmail.com>
Mon, 28 Jun 2021 08:49:37 +0000 (10:49 +0200)
commit961e9e6af65ef097678c57fe5f1c18b825eb723f
treeb9bddcf9684b4b12ab2acfa91909df0c09c5c5c9
parent26d864b44b9d3326984a7041124aa0f9e8ebc5cb
[clang-tidy] Extend 'bugprone-easily-swappable-parameters' with optionally considering differently qualified types mixable

Adds a relaxation option QualifiersMix which will make the check report for
cases where parameters refer to the same type if they only differ in qualifiers.

This makes cases, such as the following, not warned about by default, produce
a warning.

    void* memcpy(void* dst, const void* src, unsigned size) {}

However, unless people meticulously const their local variables, unfortunately,
even such a function carry a potential swap:

    T* obj = new T; // Not const!!!
    void* buf = malloc(sizeof(T));

    memcpy(obj, buf, sizeof(T));
    //     ^~~  ^~~ accidental swap here, even though the interface "specified" a const.

Reviewed By: aaron.ballman

Differential Revision: http://reviews.llvm.org/D96355
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c