arphaman updated this revision to Diff 75279. arphaman marked an inline comment as done. arphaman added a comment.
The updated patch adds a comment to the modified code as request by Manman. Repository: rL LLVM https://reviews.llvm.org/D25777 Files: lib/Sema/TreeTransform.h test/SemaCXX/designated-initializers.cpp 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 <typename T> struct Foo { + struct SubFoo { + int bar1; + int bar2; + }; + + static void Test() { SubFoo sf = {.bar1 = 10, .bar2 = 20}; } // Expected no warning +}; + +void foo() { + Foo<int>::Test(); + Foo<bool>::Test(); + Foo<float>::Test(); +} + +template <typename T> 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<int>::Test(); // expected-note {{in instantiation of member function 'Bar<int>::Test' requested here}} + Bar<bool>::Test(); // expected-note {{in instantiation of member function 'Bar<bool>::Test' requested here}} +} Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -8923,6 +8923,12 @@ Desig.AddDesignator(Designator::getField(D.getFieldName(), D.getDotLoc(), D.getFieldLoc())); + if (D.getField()) + // Ensure that the designator expression is rebuilt when a field + // designator was already assigned to a specific FieldDecl because + // that FieldDecl may be incorrect in the transformed AST if it refers + // to a FieldDecl that has been transformed as well. + 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 <typename T> struct Foo { + struct SubFoo { + int bar1; + int bar2; + }; + + static void Test() { SubFoo sf = {.bar1 = 10, .bar2 = 20}; } // Expected no warning +}; + +void foo() { + Foo<int>::Test(); + Foo<bool>::Test(); + Foo<float>::Test(); +} + +template <typename T> 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<int>::Test(); // expected-note {{in instantiation of member function 'Bar<int>::Test' requested here}} + Bar<bool>::Test(); // expected-note {{in instantiation of member function 'Bar<bool>::Test' requested here}} +} Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -8923,6 +8923,12 @@ Desig.AddDesignator(Designator::getField(D.getFieldName(), D.getDotLoc(), D.getFieldLoc())); + if (D.getField()) + // Ensure that the designator expression is rebuilt when a field + // designator was already assigned to a specific FieldDecl because + // that FieldDecl may be incorrect in the transformed AST if it refers + // to a FieldDecl that has been transformed as well. + ExprChanged = true; continue; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits