Skip to content

Commit be7678e

Browse files
committed
[clang] Enable the -Wdangling-capture diagnostic by default.
1 parent 0876c11 commit be7678e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,15 @@ Improvements to Clang's diagnostics
664664
bool operator==(const C&) = default;
665665
};
666666

667+
- Clang now emits `-Wdangling-capture` diangostic when a STL container captures a dangling reference.
668+
669+
.. code-block:: c++
670+
671+
void test() {
672+
std::vector<std::string_view> views;
673+
views.push_back(std::string("123")); // warning
674+
}
675+
667676
Improvements to Clang's time-trace
668677
----------------------------------
669678

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10237,10 +10237,10 @@ def warn_dangling_pointer_assignment : Warning<
1023710237
InGroup<DanglingAssignment>;
1023810238
def warn_dangling_reference_captured : Warning<
1023910239
"object whose reference is captured by '%0' will be destroyed at the end of "
10240-
"the full-expression">, InGroup<DanglingCapture>, DefaultIgnore;
10240+
"the full-expression">, InGroup<DanglingCapture>;
1024110241
def warn_dangling_reference_captured_by_unknown : Warning<
1024210242
"object whose reference is captured will be destroyed at the end of "
10243-
"the full-expression">, InGroup<DanglingCapture>, DefaultIgnore;
10243+
"the full-expression">, InGroup<DanglingCapture>;
1024410244

1024510245
// For non-floating point, expressions of the form x == x or x != x
1024610246
// should result in a warning, since these always evaluate to a constant.

0 commit comments

Comments
 (0)