diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 3 | ||||
-rw-r--r-- | clang/test/SemaCXX/warn-dangling-local.cpp | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 3ee5ec4a492..be0a74d8f85 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6570,7 +6570,8 @@ static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, [&](IndirectLocalPath &Path, Local L, ReferenceKind RK) -> bool { if (auto *DRE = dyn_cast<DeclRefExpr>(L)) { auto *VD = dyn_cast<VarDecl>(DRE->getDecl()); - if (VD && VD->getType().isConstQualified() && VD->getInit()) { + if (VD && VD->getType().isConstQualified() && VD->getInit() && + !isVarOnPath(Path, VD)) { Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD}); visitLocalsRetainedByInitializer(Path, VD->getInit(), Visit, true); } diff --git a/clang/test/SemaCXX/warn-dangling-local.cpp b/clang/test/SemaCXX/warn-dangling-local.cpp index 19a722f84d1..5c1d5697294 100644 --- a/clang/test/SemaCXX/warn-dangling-local.cpp +++ b/clang/test/SemaCXX/warn-dangling-local.cpp @@ -18,3 +18,9 @@ void f() { // points to, which doesn't live long enough. int *const &s = (int *const &)T{1, 2, 3}; // expected-warning {{temporary bound to local reference 's' will be destroyed at the end of the full-expression}} } + +// PR38355 +void g() { + const int a[] = {a[0]}; + const int b[] = {a[0]}; +} |