Skip to content

Commit 6993798

Browse files
authored
[clang-tidy] Ignore unevaluated context in bugprone-optional-value-conversion (#90410)
Ignore optionals in unevaluated context, like static_assert or decltype. Closes #89593
1 parent bd67986 commit 6993798

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
7171
ofClass(matchers::matchesAnyListedName(OptionalTypes)))),
7272
hasType(ConstructTypeMatcher),
7373
hasArgument(0U, ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
74-
StdMoveCallMatcher))))
74+
StdMoveCallMatcher))),
75+
unless(anyOf(hasAncestor(typeLoc()),
76+
hasAncestor(expr(matchers::hasUnevaluatedContext())))))
7577
.bind("expr"),
7678
this);
7779
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ Changes in existing checks
204204
eliminating false positives resulting from direct usage of bitwise operators
205205
within parentheses.
206206

207+
- Improved :doc:`bugprone-optional-value-conversion
208+
<clang-tidy/checks/bugprone/optional-value-conversion>` check by eliminating
209+
false positives resulting from use of optionals in unevaluated context.
210+
207211
- Improved :doc:`bugprone-suspicious-include
208212
<clang-tidy/checks/bugprone/suspicious-include>` check by replacing the local
209213
options `HeaderFileExtensions` and `ImplementationFileExtensions` by the

clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,6 @@ void correct(std::optional<int> param)
210210
std::optional<long>* p2 = &p;
211211
takeOptionalValue(p2->value_or(5U));
212212
takeOptionalRef(p2->value_or(5U));
213+
214+
using Type = decltype(takeOptionalValue(*param));
213215
}

0 commit comments

Comments
 (0)