brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · cfea1c8 Raw
53 lines · plain
1.. title:: clang-tidy - misc-throw-by-value-catch-by-reference2 3misc-throw-by-value-catch-by-reference4======================================5 6`cert-err09-cpp` and `cert-err61-cpp` redirect here as aliases of this check.7 8Finds violations of the rule "Throw by value, catch by reference" presented for9example in "C++ Coding Standards" by H. Sutter and A. Alexandrescu, as well as10the CERT C++ Coding Standard rule `ERR61-CPP. Catch exceptions by lvalue11reference <https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR61-CPP.+Catch+exceptions+by+lvalue+reference>`_.12 13 14Exceptions:15  * Throwing string literals will not be flagged despite being a pointer. They16    are not susceptible to slicing and the usage of string literals is17    idiomatic.18  * Catching character pointers (``char``, ``wchar_t``, unicode character19    types) will not be flagged to allow catching string literals.20  * Moved named values will not be flagged as not throwing an anonymous21    temporary. In this case we can be sure that the user knows that the object22    can't be accessed outside catch blocks handling the error.23  * Throwing function parameters will not be flagged as not throwing an24    anonymous temporary. This allows helper functions for throwing.25  * Re-throwing caught exception variables will not be flagged as not throwing26    an anonymous temporary. Although this can usually be done by just writing27    ``throw;`` it happens often enough in real code.28 29Options30-------31 32.. option:: CheckThrowTemporaries33 34   Triggers detection of violations of the CERT recommendation ERR09-CPP. Throw35   anonymous temporaries.36   Default is `true`.37 38.. option:: WarnOnLargeObject39 40   Also warns for any large, trivial object caught by value. Catching a large41   object by value is not dangerous but affects the performance negatively. The42   maximum size of an object allowed to be caught without warning can be set43   using the `MaxSize` option.44   Default is `false`.45 46.. option:: MaxSize47 48   Determines the maximum size of an object allowed to be caught without49   warning. Only applicable if :option:`WarnOnLargeObject` is set to `true`. If50   the option is set by the user to `std::numeric_limits<uint64_t>::max()` then51   it reverts to the default value.52   Default is the size of `size_t`.53