Skip to content

clang does not warn about uninitialized reads in lambdas #128058

@nico

Description

@nico

This warns (as it should):

$ cat test.cc
struct S {};

void g() {
  S s1 = s1;
}
$ out/gn/bin/clang -c test.cc
test.cc:4:10: warning: variable 's1' is uninitialized when used within its own initialization [-Wuninitialized]
    4 |   S s1 = s1;
      |     ~~   ^~
1 warning generated.

This doesn't (but should, too):

$ cat test.cc
struct S {};

void g() {
  S s2 = [&]() { return s2; }();
}
$ out/gn/bin/clang -c test.cc
# No diag

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions