[PATCH] D28705: [Sema] Fix bug in handling of designated initializer

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 18:46:37 PST 2017


ahatanak updated this revision to Diff 84418.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Address review comments.


https://reviews.llvm.org/D28705

Files:
  lib/Sema/SemaInit.cpp
  test/SemaCXX/designated-initializers-base-class.cpp


Index: test/SemaCXX/designated-initializers-base-class.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/designated-initializers-base-class.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -std=c++1z -fsyntax-only -verify -Winitializer-overrides
+// expected-no-diagnostics
+
+struct B {
+  int x;
+};
+
+struct D : B {
+  int y;
+};
+
+void test() { D d = {1, .y = 2}; }
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2237,6 +2237,10 @@
     }
 
     unsigned FieldIndex = 0;
+
+    if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
+      FieldIndex = CXXRD->getNumBases();
+
     for (auto *FI : RT->getDecl()->fields()) {
       if (FI->isUnnamedBitfield())
         continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28705.84418.patch
Type: text/x-patch
Size: 843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170114/675ac736/attachment.bin>


More information about the cfe-commits mailing list