forked from mirrors/gecko-dev
Differential Revision: https://phabricator.services.mozilla.com/D3980 --HG-- rename : tools/clang-tidy/test/misc-bool-pointer-implicit-conversion.cpp => tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp rename : tools/clang-tidy/test/misc-forward-declaration-namespace.cpp => tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp rename : tools/clang-tidy/test/misc-macro-repeated-side-effects.cpp => tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp rename : tools/clang-tidy/test/misc-string-constructor.cpp => tools/clang-tidy/test/bugprone-string-constructor.cpp rename : tools/clang-tidy/test/misc-string-integer-assignment.cpp => tools/clang-tidy/test/bugprone-string-integer-assignment.cpp rename : tools/clang-tidy/test/misc-suspicious-missing-comma.cpp => tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp rename : tools/clang-tidy/test/misc-swapped-arguments.cpp => tools/clang-tidy/test/bugprone-swapped-arguments.cpp rename : tools/clang-tidy/test/misc-unused-raii.cpp => tools/clang-tidy/test/bugprone-unused-raii.cpp extra : moz-landing-system : lando
28 lines
696 B
C++
28 lines
696 B
C++
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-macro-repeated-side-effects.html
|
|
|
|
#define MACRO_WITHOUT_REPEATED_ARG(x) (x)
|
|
#define MACRO_WITH_REPEATED_ARG(x) ((x) + (x))
|
|
|
|
static int g;
|
|
|
|
int function_with_side_effects(int i)
|
|
{
|
|
g += i;
|
|
return g;
|
|
}
|
|
|
|
void test()
|
|
{
|
|
int i;
|
|
i = MACRO_WITHOUT_REPEATED_ARG(1); // OK
|
|
i = MACRO_WITH_REPEATED_ARG(1); // OK
|
|
|
|
i = MACRO_WITHOUT_REPEATED_ARG(i); // OK
|
|
i = MACRO_WITH_REPEATED_ARG(i); // OK
|
|
|
|
i = MACRO_WITHOUT_REPEATED_ARG(function_with_side_effects(i)); // OK
|
|
i = MACRO_WITH_REPEATED_ARG(function_with_side_effects(i)); // NO WARNING
|
|
|
|
i = MACRO_WITHOUT_REPEATED_ARG(i++); // OK
|
|
i = MACRO_WITH_REPEATED_ARG(i++); // WARNING
|
|
}
|