]> granicus.if.org Git - clang/commitdiff
PR38355 Prevent infinite recursion when checking initializer lifetime if
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 30 Jul 2018 07:19:54 +0000 (07:19 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 30 Jul 2018 07:19:54 +0000 (07:19 +0000)
an initializer is self-referential.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338230 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/warn-dangling-local.cpp

index 3ee5ec4a4929e197ef7bdbb1c7d1d5e1ca1fb40a..be0a74d8f85a65bc1a518ef82453a4cd3c12f2cd 100644 (file)
@@ -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);
           }
index 19a722f84d16e6a471e1551f9313a4e780609755..5c1d56972945c98d88a8245a34433167c15edb19 100644 (file)
@@ -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]};
+}