Kaydet (Commit) 3b48c945 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:unusedenumconstants ignore common pattern

Ignore a common pattern that does not introduce any new information,
merely removes information.

Change-Id: I37da352c9295ec12b9dac7aad4b4792a6d726b0d
Reviewed-on: https://gerrit.libreoffice.org/64255
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 83102e4f
......@@ -81,6 +81,8 @@ struct Test4 : public Test4Base
};
};
//-----------------------------------------------------------------------------------
// check that conditional operator walks up the tree
namespace test5
{
......@@ -93,4 +95,24 @@ enum Enum
Enum foo(int x) { return x == 1 ? Enum::ONE : Enum::TWO; }
};
//-----------------------------------------------------------------------------------
// Ignore a common pattern that does not introduce any new information, merely removes
// information.
enum class Enum6
{
Modules = 0x01, // expected-error {{write Modules [loplugin:unusedenumconstants]}}
Top = 0x02,
};
namespace o3tl
{
template <> struct typed_flags<Enum6> : is_typed_flags<Enum6, 0x03>
{
};
}
void test6()
{
Enum6 foo = Enum6::Modules;
foo &= ~Enum6::Top;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -174,12 +174,24 @@ walk_up:
else if (const CXXOperatorCallExpr * operatorCall = dyn_cast<CXXOperatorCallExpr>(parent))
{
auto oo = operatorCall->getOperator();
// if assignment op
if (oo == OO_Equal || oo == OO_StarEqual || oo == OO_SlashEqual || oo == OO_PercentEqual
if (oo == OO_AmpEqual)
{
// Ignore a common pattern that does not introduce any new information, merely removes
// information: foo &= ~Enum6::Top
bool found = false;
if (auto innerOperatorCall = dyn_cast<CXXOperatorCallExpr>(operatorCall->getArg(1)))
{
found = innerOperatorCall->getOperator() == OO_Tilde;
}
if (!found)
bWrite = true;
}
// if assignment op
else if (oo == OO_Equal || oo == OO_StarEqual || oo == OO_SlashEqual || oo == OO_PercentEqual
|| oo == OO_PlusEqual || oo == OO_MinusEqual || oo == OO_LessLessEqual
|| oo == OO_AmpEqual || oo == OO_CaretEqual || oo == OO_PipeEqual)
|| oo == OO_CaretEqual || oo == OO_PipeEqual)
bWrite = true;
// else if comparison op
// else if comparison op
else if (oo == OO_AmpAmp || oo == OO_PipePipe || oo == OO_Subscript
|| oo == OO_Less || oo == OO_Greater || oo == OO_LessEqual || oo == OO_GreaterEqual || oo == OO_EqualEqual || oo == OO_ExclaimEqual)
bRead = true;
......
......@@ -105,6 +105,11 @@ def is_ignore(srcLoc):
"sc/source/filter/inc/flttypes.hxx", # BiffTyp
"sc/inc/optutil.hxx", # ScOptionsUtil::KeyBindingType
"include/sfx2/chalign.hxx", # SfxChildAlignment
"drawinglayer/source/tools/emfpbrush.hxx",
"drawinglayer/source/tools/emfppen.cxx",
"include/oox/ppt/animationspersist.hxx",
"include/vcl/fontcapabilities.hxx",
"sw/inc/poolfmt.hxx",
# unit test code
"cppu/source/uno/check.cxx",
# general weird nonsense going on
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment