Skip to content

Commit e87c8e3

Browse files
authored
Merge pull request #4978 from randombit/jack/clang-tidy-misc-redundant-expression
Enable and fix clang-tidy warning misc-redundant-expression
2 parents 7e46850 + b558818 commit e87c8e3

6 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Checks: >
2727
-cppcoreguidelines-prefer-member-initializer,
2828
-misc-const-correctness,
2929
-misc-include-cleaner,
30-
-misc-redundant-expression,
3130
-misc-misplaced-const,
3231
-misc-confusable-identifiers,
3332
-modernize-pass-by-value,

src/scripts/dev_tools/run_clang_tidy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
'cppcoreguidelines-prefer-member-initializer',
5959
'misc-const-correctness', # pretty noisy
6060
'misc-include-cleaner',
61-
'misc-redundant-expression', # BigInt seems to confuse clang-tidy
6261
'misc-misplaced-const',
6362
'misc-confusable-identifiers',
6463
'modernize-pass-by-value',

src/tests/test_ec_group.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class EC_Point_Arithmetic_Tests final : public Test {
685685
result.start_timer();
686686

687687
const auto one = Botan::EC_Scalar::one(group);
688-
const auto zero = one - one;
688+
const auto zero = one - one; // NOLINT(*-redundant-expression)
689689
const auto g = Botan::EC_AffinePoint::generator(group);
690690
const auto g_bytes = g.serialize_uncompressed();
691691

@@ -716,7 +716,7 @@ class EC_Point_Arithmetic_Tests final : public Test {
716716
result.confirm("Scalar::zero is zero", zero.is_zero());
717717
result.confirm("(zero+zero) is zero", (zero + zero).is_zero());
718718
result.confirm("(zero*zero) is zero", (zero * zero).is_zero());
719-
result.confirm("(zero-zero) is zero", (zero - zero).is_zero());
719+
result.confirm("(zero-zero) is zero", (zero - zero).is_zero()); // NOLINT(*-redundant-expression)
720720

721721
const auto neg_zero = zero.negate();
722722
result.confirm("zero.negate() is zero", neg_zero.is_zero());
@@ -726,7 +726,7 @@ class EC_Point_Arithmetic_Tests final : public Test {
726726
result.confirm("(nz+zero) is zero", (neg_zero + zero).is_zero());
727727

728728
result.confirm("Scalar::one is not zero", !one.is_zero());
729-
result.confirm("(one-one) is zero", (one - one).is_zero());
729+
result.confirm("(one-one) is zero", (one - one).is_zero()); // NOLINT(*-redundant-expression)
730730
result.confirm("(one+one.negate()) is zero", (one + one.negate()).is_zero());
731731
result.confirm("(one.negate()+one) is zero", (one.negate() + one).is_zero());
732732

src/tests/test_ecc_pointmul.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ECC_Mul2_Inf_Tests final : public Test {
186186
const auto neg_r = r.negate();
187187
const auto neg_r2 = neg_r + neg_r;
188188

189-
const auto zero = r - r;
189+
const auto zero = r - r; // NOLINT(*-redundant-expression)
190190
result.confirm("Computed EC_Scalar is zero", zero.is_zero());
191191

192192
const auto g2 = g.add(g);
@@ -280,7 +280,7 @@ class ECC_Scalar_Arithmetic_Tests final : public Test {
280280
const Botan::EC_Group& group,
281281
Botan::RandomNumberGenerator& rng) const {
282282
const auto one = Botan::EC_Scalar::one(group);
283-
const auto zero = one - one;
283+
const auto zero = one - one; // NOLINT(*-redundant-expression)
284284
const auto two = one + one;
285285

286286
const size_t order_bytes = group.get_order_bytes();

src/tests/test_ecdh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class ECDH_AllGroups_Tests : public Test {
7474
// Regression test: prohibit loading an all-zero private key
7575
result.test_throws<Botan::Invalid_Argument>("all-zero private key is unacceptable", [&] {
7676
const auto one = Botan::EC_Scalar::one(group);
77-
Botan::ECDH_PrivateKey(group, one - one);
77+
const auto zero = one - one; // NOLINT(*-redundant-expression)
78+
Botan::ECDH_PrivateKey(group, zero);
7879
});
7980

8081
// Regression test: prohibit loading a public point that is the identity (point at infinity)

src/tests/test_kyber.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "test_rng.h"
1717
#include "tests.h"
1818

19-
#include <cmath>
2019
#include <iterator>
2120
#include <memory>
2221

@@ -379,6 +378,7 @@ void test_compress_roundtrip(Test::Result& result) {
379378

380379
result.start_timer();
381380

381+
// NOLINTNEXTLINE(*-redundant-expression)
382382
for(uint16_t x = 0; x < q && x < (1 << d); ++x) {
383383
const uint16_t c = Kyber_Algos::compress<d>(Kyber_Algos::decompress<d>(x));
384384
if(x != c) {

0 commit comments

Comments
 (0)