File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -33,14 +33,20 @@ handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
3333
3434ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue (
3535 const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle) {
36+
37+ const auto TemporaryExpr = anyOf (
38+ cxxBindTemporaryExpr (),
39+ cxxFunctionalCastExpr (
40+ hasCastKind (CK_ConstructorConversion),
41+ hasSourceExpression (ignoringParenImpCasts (cxxBindTemporaryExpr ()))));
3642 // If a ternary operator returns a temporary value, then both branches hold a
3743 // temporary value. If one of them is not a temporary then it must be copied
3844 // into one to satisfy the type of the operator.
3945 const auto TemporaryTernary = conditionalOperator (
40- hasTrueExpression (ignoringParenImpCasts (cxxBindTemporaryExpr () )),
41- hasFalseExpression (ignoringParenImpCasts (cxxBindTemporaryExpr () )));
46+ hasTrueExpression (ignoringParenImpCasts (TemporaryExpr )),
47+ hasFalseExpression (ignoringParenImpCasts (TemporaryExpr )));
4248
43- return handleFrom (IsAHandle, anyOf (cxxBindTemporaryExpr () , TemporaryTernary));
49+ return handleFrom (IsAHandle, anyOf (TemporaryExpr , TemporaryTernary));
4450}
4551
4652ast_matchers::internal::Matcher<RecordDecl> isASequence () {
Original file line number Diff line number Diff line change @@ -207,6 +207,11 @@ New check aliases
207207Changes in existing checks
208208^^^^^^^^^^^^^^^^^^^^^^^^^^
209209
210+ - Improved :doc: `bugprone-dangling-handle
211+ <clang-tidy/checks/bugprone/dangling-handle>` check to support functional
212+ casting during type conversions at variable initialization, now with improved
213+ compatibility for C++17 and later versions.
214+
210215- Improved :doc: `bugprone-lambda-function-name
211216 <clang-tidy/checks/bugprone/lambda-function-name>` check by adding option
212217 `IgnoreMacros ` to ignore warnings in macros.
Original file line number Diff line number Diff line change @@ -108,6 +108,14 @@ void Positives() {
108108 std::string_view view4 (ReturnsAString ());
109109 // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives
110110 // CHECK-MESSAGES-CXX17: [[@LINE-2]]:26: warning: std::basic_string_view outlives
111+
112+ std::string_view view5 = std::string (" test" );
113+ // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
114+ // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
115+
116+ std::string_view view6 = std::string{" test" };
117+ // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
118+ // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
111119}
112120
113121void OtherTypes () {
You can’t perform that action at this time.
0 commit comments