[PATCH] D28705: [Sema] Fix bug in handling of designated initializer
Reid Kleckner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 13 16:31:19 PST 2017
rnk added a comment.
What happens with virtual bases?
struct B { int x; };
struct D : virtual B { int y; };
void test() { D d = {1, .y = 2}; }
================
Comment at: lib/Sema/SemaInit.cpp:2250
+ if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
+ FieldIndex += CXXRD->getNumBases();
----------------
Do this before counting fields, IMO it's more intuitive.
================
Comment at: test/SemaCXX/designated-initializers-base-class.cpp:1
+// RUN: %clang_cc1 %s -std=c++1z -ast-dump | FileCheck %s
+
----------------
This might be less fragile as an IRGen test. Alternatively, this is a good expected-no-diagnostic test:
void test() { D d = {1, .y = 2}; }
Right now we emit `warning: initializer overrides prior initialization of this subobject`, which is obviously wrong.
https://reviews.llvm.org/D28705
More information about the cfe-commits
mailing list