1.. title:: clang-tidy - modernize-make-shared
2
3modernize-make-shared
4=====================
5
6This check finds the creation of ``std::shared_ptr`` objects by explicitly
7calling the constructor and a ``new`` expression, and replaces it with a call
8to ``std::make_shared``.
9
10.. code-block:: c++
11
12  auto my_ptr = std::shared_ptr<MyPair>(new MyPair(1, 2));
13
14  // becomes
15
16  auto my_ptr = std::make_shared<MyPair>(1, 2);
17
18This check also finds calls to ``std::shared_ptr::reset()`` with a ``new``
19expression, and replaces it with a call to ``std::make_shared``.
20
21.. code-block:: c++
22
23  my_ptr.reset(new MyPair(1, 2));
24
25  // becomes
26
27  my_ptr = std::make_shared<MyPair>(1, 2);
28
29Options
30-------
31
32.. option:: MakeSmartPtrFunction
33
34   A string specifying the name of make-shared-ptr function. Default is
35   `std::make_shared`.
36
37.. option:: MakeSmartPtrFunctionHeader
38
39   A string specifying the corresponding header of make-shared-ptr function.
40   Default is `memory`.
41
42.. option:: IncludeStyle
43
44   A string specifying which include-style is used, `llvm` or `google`. Default
45   is `llvm`.
46
47.. option:: IgnoreMacros
48
49   If set to `true`, the check will not give warnings inside macros. Default
50   is `true`.
51
52.. option:: IgnoreDefaultInitialization
53
54   If set to non-zero, the check does not suggest edits that will transform
55   default initialization into value initialization, as this can cause
56   performance regressions. Default is `1`.
57