Skip to content

Commit

Permalink
[clang] Enable the -Wdangling-capture diagnostic by default. (llvm#11…
Browse files Browse the repository at this point in the history
…9685)

We have tested this diagnostics internally, and we don't find see any
issues.
  • Loading branch information
hokein authored Dec 12, 2024
1 parent 010d011 commit f229ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ Improvements to Clang's diagnostics
bool operator==(const C&) = default;
};

- Clang now emits `-Wdangling-capture` diangostic when a STL container captures a dangling reference.

.. code-block:: c++

void test() {
std::vector<std::string_view> views;
views.push_back(std::string("123")); // warning
}

Improvements to Clang's time-trace
----------------------------------

Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10237,10 +10237,10 @@ def warn_dangling_pointer_assignment : Warning<
InGroup<DanglingAssignment>;
def warn_dangling_reference_captured : Warning<
"object whose reference is captured by '%0' will be destroyed at the end of "
"the full-expression">, InGroup<DanglingCapture>, DefaultIgnore;
"the full-expression">, InGroup<DanglingCapture>;
def warn_dangling_reference_captured_by_unknown : Warning<
"object whose reference is captured will be destroyed at the end of "
"the full-expression">, InGroup<DanglingCapture>, DefaultIgnore;
"the full-expression">, InGroup<DanglingCapture>;

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

0 comments on commit f229ea2

Please sign in to comment.