26 lines · plain
1.. title:: clang-tidy - misc-misplaced-const2 3misc-misplaced-const4====================5 6This check diagnoses when a ``const`` qualifier is applied to a ``typedef``/7``using`` to a pointer type rather than to the pointee, because such constructs8are often misleading to developers because the ``const`` applies to the pointer9rather than the pointee.10 11For instance, in the following code, the resulting type is ``int * const``12rather than ``const int *``:13 14.. code-block:: c++15 16 typedef int *int_ptr;17 void f(const int_ptr ptr) {18 *ptr = 0; // potentially quite unexpectedly the int can be modified here19 ptr = 0; // does not compile20 }21 22The check does not diagnose when the underlying ``typedef``/``using`` type is a23pointer to a ``const`` type or a function pointer type. This is because the24``const`` qualifier is less likely to be mistaken because it would be redundant25(or disallowed) on the underlying pointee type.26