fune/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp
Andi-Bogdan Postelnicu 34a6c4ff8f Bug 1466427 - Migrate clang-tidy package from 5.0.1 to 7.0.0-rc2. r=glandium,janx
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
2018-08-24 12:39:58 +00:00

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
}