Skip to content

Commit f229ea2

Browse files
authored
[clang] Enable the -Wdangling-capture diagnostic by default. (#119685)
We have tested this diagnostics internally, and we don't find see any issues.
1 parent 010d011 commit f229ea2

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
@@ -666,6 +666,15 @@ Improvements to Clang's diagnostics
666666
bool operator==(const C&) = default;
667667
};
668668

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

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)