From: David Majnemer Date: Fri, 21 Aug 2015 06:44:10 +0000 (+0000) Subject: [Sema] Don't crash when diagnosing hack in libstdc++ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6af146a7c6b0aafedbb3ebbb0d3af9a7f6cd445;p=clang [Sema] Don't crash when diagnosing hack in libstdc++ While working around a bug in certain standard library implementations, we would try to diagnose the issue so that library implementors would fix their code. However, we assumed an entity being initialized was a non-static data member subobject when other circumstances are possible. This fixes PR24526. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245675 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index adec512693..1b958ae782 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -443,8 +443,11 @@ ExprResult InitListChecker::PerformEmptyInit(Sema &SemaRef, if (!VerifyOnly) { SemaRef.Diag(CtorDecl->getLocation(), diag::warn_invalid_initializer_from_system_header); - SemaRef.Diag(Entity.getDecl()->getLocation(), - diag::note_used_in_initialization_here); + if (Entity.getKind() == InitializedEntity::EK_Member) + SemaRef.Diag(Entity.getDecl()->getLocation(), + diag::note_used_in_initialization_here); + else if (Entity.getKind() == InitializedEntity::EK_ArrayElement) + SemaRef.Diag(Loc, diag::note_used_in_initialization_here); } } } diff --git a/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp b/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp index 774745777c..f9e0a5c0a1 100644 --- a/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp +++ b/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp @@ -9,7 +9,7 @@ namespace __debug { template class vector { public: - explicit vector() {} // expected-warning{{should not be explicit}} + explicit vector() {} // expected-warning 2 {{should not be explicit}} }; } } @@ -19,5 +19,6 @@ public: #include __FILE__ struct { int a, b; std::__debug::vector c; } e[] = { {1, 1} }; // expected-note{{used in initialization here}} - +// expected-warning@+1 {{expression with side effects has no effect in an unevaluated context}} +decltype(new std::__debug::vector[1]{}) x; // expected-note{{used in initialization here}} #endif