diff options
author | Sergio Martins <smartins@kde.org> | 2021-07-27 22:53:04 +0100 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2021-07-27 22:53:04 +0100 |
commit | c929ad0a23d58737f1e39edc79fe671ad05f4c8e (patch) | |
tree | c65a4b4968d7ee074070874b8acdfbbf0ff26d2f | |
parent | 02a5e362793993c47b8d6af96fcdfc5a916b4c1c (diff) |
unexpected-flag-enumerator-value: Don't warn when value is negative
As seen in Qt, this is very intentional
-rw-r--r-- | src/checks/manuallevel/unexpected-flag-enumerator-value.cpp | 2 | ||||
-rw-r--r-- | tests/unexpected-flag-enumerator-value/main.cpp | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/checks/manuallevel/unexpected-flag-enumerator-value.cpp b/src/checks/manuallevel/unexpected-flag-enumerator-value.cpp index b953f622..6d1bf226 100644 --- a/src/checks/manuallevel/unexpected-flag-enumerator-value.cpp +++ b/src/checks/manuallevel/unexpected-flag-enumerator-value.cpp @@ -124,7 +124,7 @@ void UnexpectedFlagEnumeratorValue::VisitDecl(clang::Decl *decl) for (EnumConstantDecl* enumerator : enumerators) { const auto &initVal = enumerator->getInitVal(); - if (!initVal.isPowerOf2() && !initVal.isNullValue()){ + if (!initVal.isPowerOf2() && !initVal.isNullValue() && !initVal.isNegative()){ if (isIntentionallyNotPowerOf2(enumerator)) continue; const auto value = enumerator->getInitVal().getLimitedValue(); diff --git a/tests/unexpected-flag-enumerator-value/main.cpp b/tests/unexpected-flag-enumerator-value/main.cpp index 3d7884df..40d3e885 100644 --- a/tests/unexpected-flag-enumerator-value/main.cpp +++ b/tests/unexpected-flag-enumerator-value/main.cpp @@ -81,3 +81,12 @@ enum class AlsoConsecutive { WHITE = 5, LAST = WHITE }; + +enum class WithNegative +{ + V1 = 1, + V2 = 2, + V4 = 4, + V8 = 8, + VFoo = -1 +}; |