Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -8923,6 +8923,19 @@ Desig.AddDesignator(Designator::getField(D.getFieldName(), D.getDotLoc(), D.getFieldLoc())); + if (D.getField()) { + FieldDecl *Field = dyn_cast_or_null( + getDerived().TransformDecl(D.getFieldLoc(), D.getField())); + if (Field != D.getField()) + // Rebuild the expression when the transformed FieldDecl is + // different to the already assigned FieldDecl. + ExprChanged = true; + } else { + // Ensure that the designator expression is rebuilt when there isn't + // a resolved FieldDecl in the designator as we don't want to assign + // a FieldDecl to a pattern designator that will be instantiated again. + ExprChanged = true; + } continue; } Index: test/SemaCXX/designated-initializers.cpp =================================================================== --- /dev/null +++ test/SemaCXX/designated-initializers.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Winitializer-overrides %s + +template struct Foo { + struct SubFoo { + int bar1; + int bar2; + }; + + static void Test() { SubFoo sf = {.bar1 = 10, .bar2 = 20}; } // Expected no warning +}; + +void foo() { + Foo::Test(); + Foo::Test(); + Foo::Test(); +} + +template struct Bar { + struct SubFoo { + int bar1; + int bar2; + }; + + static void Test() { SubFoo sf = {.bar1 = 10, // expected-note 2 {{previous initialization is here}} + .bar1 = 20}; } // expected-warning 2 {{initializer overrides prior initialization of this subobject}} +}; + +void bar() { + Bar::Test(); // expected-note {{in instantiation of member function 'Bar::Test' requested here}} + Bar::Test(); // expected-note {{in instantiation of member function 'Bar::Test' requested here}} +}