@@ -587,10 +587,7 @@ Prefer C++-style casts
587
587
^^^^^^^^^^^^^^^^^^^^^^
588
588
589
589
When casting, use ``static_cast ``, ``reinterpret_cast ``, and ``const_cast ``,
590
- rather than C-style casts. There are two exceptions to this:
591
-
592
- * When casting to ``void `` to suppress warnings about unused variables (as an
593
- alternative to ``[[maybe_unused]] ``). Prefer C-style casts in this instance.
590
+ rather than C-style casts. There is one exception to this:
594
591
595
592
* When casting between integral types (including enums that are not strongly-
596
593
typed), functional-style casts are permitted as an alternative to
@@ -1286,17 +1283,17 @@ value" warning when assertions are disabled. For example, this code will warn:
1286
1283
1287
1284
These are two interesting different cases. In the first case, the call to
1288
1285
``V.size() `` is only useful for the assert, and we don't want it executed when
1289
- assertions are disabled. Code like this should move the call into the assert
1286
+ assertions are disabled. Code like this should move the call into the assert
1290
1287
itself. In the second case, the side effects of the call must happen whether
1291
- the assert is enabled or not. In this case, the value should be cast to void to
1292
- disable the warning. To be specific, it is preferred to write the code like
1293
- this:
1288
+ the assert is enabled or not. In this case, the value should be defined using
1289
+ the `` [[maybe_unused]] `` attribute disable the warning. To be specific, it is
1290
+ preferred to write the code like this:
1294
1291
1295
1292
.. code-block :: c++
1296
1293
1297
1294
assert(V.size() > 42 && "Vector smaller than it should be");
1298
1295
1299
- bool NewToSet = Myset.insert(Value); (void)NewToSet ;
1296
+ [[maybe_unused]] bool NewToSet = Myset.insert(Value);
1300
1297
assert(NewToSet && "The value shouldn't be in the set yet");
1301
1298
1302
1299
Do Not Use ``using namespace std ``
0 commit comments