Skip to content

Commit eee9e3f

Browse files
committed
fix
1 parent d9a5f37 commit eee9e3f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,26 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
8585
// known template methods in std
8686
callExpr(
8787
argumentCountIs(1),
88-
callee(functionDecl(
89-
matchers::matchesAnyListedName(MakeSmartPtrList),
90-
hasTemplateArgument(0, refersToType(BindOptionalType)))),
88+
anyOf(
89+
// match std::make_unique std::make_shared
90+
callee(functionDecl(
91+
matchers::matchesAnyListedName(MakeSmartPtrList),
92+
hasTemplateArgument(
93+
0, refersToType(BindOptionalType)))),
94+
// match first std::make_optional by limit argument count
95+
// (1) and template count (1).
96+
// 1. template< class T > constexpr
97+
// std::optional<decay_t<T>> make_optional(T&& value);
98+
// 2. template< class T, class... Args > constexpr
99+
// std::optional<T> make_optional(Args&&... args);
100+
callee(functionDecl(templateArgumentCountIs(1),
101+
hasName(MakeOptional),
102+
returns(BindOptionalType)))),
91103
hasArgument(0, OptionalDerefMatcher)),
92104
callExpr(
93-
// match first std::make_optional by limit argument count (1)
94-
// and template count (1).
95-
// 1. template< class T > constexpr
96-
// std::optional<decay_t<T>> make_optional(T&& value);
97-
// 2. template< class T, class... Args > constexpr
98-
// std::optional<T> make_optional(Args&&... args);
105+
99106
argumentCountIs(1),
100-
callee(functionDecl(templateArgumentCountIs(1),
101-
hasName(MakeOptional),
102-
returns(BindOptionalType))),
107+
103108
hasArgument(0, OptionalDerefMatcher))),
104109
unless(anyOf(hasAncestor(typeLoc()),
105110
hasAncestor(expr(matchers::hasUnevaluatedContext())))))

clang-tools-extra/docs/ReleaseNotes.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ New check aliases
112112
Changes in existing checks
113113
^^^^^^^^^^^^^^^^^^^^^^^^^^
114114

115+
- Improved :doc:`bugprone-optional-value-conversion
116+
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
117+
conversion in argument of ``std::make_optional``.
118+
115119
- Improved :doc:`bugprone-string-constructor
116120
<clang-tidy/checks/bugprone/string-constructor>` check to find suspicious
117121
calls of ``std::string`` constructor with char pointer, start position and
@@ -124,10 +128,6 @@ Changes in existing checks
124128
no longer be needed and will be removed. Also fixing false positive from
125129
const reference accessors to objects containing optional member.
126130

127-
- Improved :doc:`bugprone-optional-value-conversion
128-
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
129-
conversion in argument of ``std::make_optional``.
130-
131131
- Improved :doc:`bugprone-unsafe-functions
132132
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
133133
additional C++ member functions to match.

0 commit comments

Comments
 (0)