Author: majnemer Date: Fri Aug 21 01:44:10 2015 New Revision: 245675 URL: http://llvm.org/viewvc/llvm-project?rev=245675&view=rev Log: [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. Modified: cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp Modified: cfe/trunk/lib/Sema/SemaInit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=245675&r1=245674&r2=245675&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug 21 01:44:10 2015 @@ -443,8 +443,11 @@ ExprResult InitListChecker::PerformEmpty 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); } } } Modified: cfe/trunk/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp?rev=245675&r1=245674&r2=245675&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp (original) +++ cfe/trunk/test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp Fri Aug 21 01:44:10 2015 @@ -9,7 +9,7 @@ namespace __debug { template <class T> 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<int> 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<int>[1]{}) x; // expected-note{{used in initialization here}} #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits