Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -2628,6 +2628,9 @@ } else llvm_unreachable("An unknown case of structured binding encountered!"); + if (BD->getType()->isReferenceType()) + V = state->getSVal(V.getAsRegion()); + Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr, ProgramPoint::PostLValueKind); Index: clang/test/Analysis/structured_bindings.cpp =================================================================== --- clang/test/Analysis/structured_bindings.cpp +++ clang/test/Analysis/structured_bindings.cpp @@ -1,9 +1,29 @@ -// RUN: %clang_analyze_cc1 -std=c++17 -analyzer-checker=core -verify %s +// RUN: %clang_analyze_cc1 -std=c++17 -analyzer-checker=core,debug.ExprInspection -verify %s + +void clang_analyzer_eval(bool); struct s { int a; }; int foo() { - auto[a] = s{1}; // FIXME: proper modelling - if (a) { - } + auto [a] = s{1}; + clang_analyzer_eval(a == 1); // expected-warning{{TRUE}} } // expected-warning{{non-void function does not return a value}} +struct s2 { + int &x; +}; + +int *foo2(s2 in) { + auto [a] = in; + return &a; +} + +int main() { + int i = 1; + s2 a{i}; + + auto *x = foo2(a); + + clang_analyzer_eval(*x == i); // expected-warning{{TRUE}} + + return 0; +}