]> granicus.if.org Git - clang/commitdiff
[Sema] Don't crash when diagnosing hack in libstdc++
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 21 Aug 2015 06:44:10 +0000 (06:44 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 21 Aug 2015 06:44:10 +0000 (06:44 +0000)
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

lib/Sema/SemaInit.cpp
test/SemaCXX/libstdcxx_explicit_init_list_hack.cpp

index adec512693f3fe4edf5d7482ca9357a34cf5ce8b..1b958ae782c8c71a4fa741efb9855f53fb60bb7e 100644 (file)
@@ -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);
         }
       }
     }
index 774745777c17d5922e84cdc5ce5753d2649b30e0..f9e0a5c0a1f02a26003e1d326eb9c6036cb21700 100644 (file)
@@ -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