
The lifetime bound warning in Clang currently only considers initializations. This patch extends the warning to include assignments. - **Support for assignments of built-in pointer types**: this is done is by reusing the existing statement-local implementation. Clang now warns if the pointer is assigned to a temporary object that being destoryed at the end of the full assignment expression. With this patch, we will detect more cases under the on-by-default diagnostic `-Wdangling`. I have added a new category for this specific diagnostic so that people can temporarily disable it if their codebase is not yet clean. This is the first step to address #63310, focusing only on pointer types. Support for C++ assignment operators will come in a follow-up patch. Fixes #54492
10 lines
310 B
C
10 lines
310 B
C
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -Wno-dangling-assignment %s
|
|
// expected-no-diagnostics
|
|
int main(void) {
|
|
char *s;
|
|
// In C++ mode, the cast creates a "char [4]" array temporary here.
|
|
s = (char []){"whatever"}; // dangling!
|
|
s = (char(*)){s};
|
|
}
|