Skip to content

Commit aaf2612

Browse files
committed
Actualize docs
1 parent af75a05 commit aaf2612

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

clang-tools-extra/clang-tidy/misc/BoolBitwiseOperationCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ static const Expr *getAcceptableCompoundsLHS(const BinaryOperator *BinOp) {
133133
BoolBitwiseOperationCheck::BoolBitwiseOperationCheck(StringRef Name,
134134
ClangTidyContext *Context)
135135
: ClangTidyCheck(Name, Context),
136-
StrictMode(Options.get("StrictMode", false)),
136+
UnsafeMode(Options.get("UnsafeMode", false)),
137137
IgnoreMacros(Options.get("IgnoreMacros", false)) {}
138138

139139
void BoolBitwiseOperationCheck::storeOptions(
140140
ClangTidyOptions::OptionMap &Opts) {
141-
Options.store(Opts, "StrictMode", StrictMode);
141+
Options.store(Opts, "UnsafeMode", UnsafeMode);
142142
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
143143
}
144144

@@ -174,7 +174,7 @@ void BoolBitwiseOperationCheck::emitWarningAndChangeOperatorsIfPossible(
174174
}
175175

176176
const bool HasSideEffects = BinOp->getRHS()->HasSideEffects(
177-
Ctx, /*IncludePossibleEffects=*/!StrictMode);
177+
Ctx, /*IncludePossibleEffects=*/!UnsafeMode);
178178
if (HasSideEffects) {
179179
DiagEmitter();
180180
return;

clang-tools-extra/clang-tidy/misc/BoolBitwiseOperationCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BoolBitwiseOperationCheck : public ClangTidyCheck {
4242
clang::ASTContext &Ctx,
4343
std::optional<bool> &RootAssignsToBoolean);
4444

45-
bool StrictMode;
45+
bool UnsafeMode;
4646
bool IgnoreMacros;
4747
};
4848

clang-tools-extra/docs/clang-tidy/checks/misc/bool-bitwise-operation.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ to implicit integer conversions and missed short-circuit evaluation.
1414

1515
bool invalid = false;
1616
invalid |= x > limit.x; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
17+
// 400 | invalid |= x > limit.x;
18+
// | ^~
19+
// | = invalid ||
1720
invalid |= y > limit.y; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
21+
// 401 | invalid |= y > limit.y;
22+
// | ^~
23+
// | = invalid ||
1824
invalid |= z > limit.z; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
25+
// 402 | invalid |= z > limit.z;
26+
// | ^~
27+
// | = invalid ||
1928
if (invalid) {
2029
// error handling
2130
}
@@ -33,24 +42,30 @@ instead of using the ``|=`` operator:
3342
// error handling
3443
}
3544

45+
It is not always a safe transformation though. The following case will warn
46+
without fix-it to preserve the semantics.
47+
48+
.. code-block:: c++
49+
50+
volatile bool invalid = false;
51+
invalid |= x > limit.x; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
52+
3653
Limitations
3754
-----------
3855

39-
* Bitwise operators inside templates aren't matched.
56+
* Bitwise operators inside templates aren't guaranteed to match.
4057

4158
.. code-block:: c++
4259

4360
template <typename X>
4461
void f(X a, X b) {
45-
a | b;
62+
a | b; // the warning may not be emited
4663
}
4764

48-
// even 'f(true, false)' (or similar) won't trigger the warning.
49-
5065
Options
5166
-------
5267

53-
.. option:: StrictMode
68+
.. option:: UnsafeMode
5469

5570
Enabling this option promotes more fix-it hints even when they might
5671
change evaluation order or skip side effects. Default value is `false`.

clang-tools-extra/test/clang-tidy/checkers/misc/bool-bitwise-operation-change-possible-side-effect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %check_clang_tidy %s misc-bool-bitwise-operation %t \
22
// RUN: -config="{CheckOptions: { \
3-
// RUN: misc-bool-bitwise-operation.StrictMode: true }}"
3+
// RUN: misc-bool-bitwise-operation.UnsafeMode: true }}"
44

55
bool function_with_possible_side_effects();
66

0 commit comments

Comments
 (0)