Suppress -Wmissing-braces warning when aggregate-initializing a struct with a single field that is itself an aggregate.

In C++, such initialization of std::array<T, N> types is guaranteed to work by
the standard, is completely idiomatic, and the "suggested" alternative from
Clang was technically invalid.

llvm-svn: 314838
diff --git a/clang/test/Sema/zero-initializer.c b/clang/test/Sema/zero-initializer.c
index 472eed9..0ab410d 100644
--- a/clang/test/Sema/zero-initializer.c
+++ b/clang/test/Sema/zero-initializer.c
@@ -6,6 +6,7 @@
 struct A { int a; };
 struct B { struct A a; };
 struct C { struct B b; };
+struct D { struct C c; int n; };
 
 int main(void)
 {
@@ -20,7 +21,8 @@
   struct bar n = { { 0 }, { 9, 9 } }; // no-warning
   struct bar o = { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
   struct C p = { 0 }; // no-warning
-  struct C q = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}}
+  struct C q = { 9 }; // warning suppressed for struct with single element
+  struct D r = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}
   f = (struct foo ) { 0 }; // no-warning
   g = (struct foo ) { 9 }; // expected-warning {{missing field 'y' initializer}}
   h = (struct foo ) { 9, 9 }; // no-warning
@@ -32,7 +34,8 @@
   n = (struct bar) { { 0 }, { 9, 9 } }; // no-warning
   o = (struct bar) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
   p = (struct C) { 0 }; // no-warning
-  q = (struct C) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}}
+  q = (struct C) { 9 }; // warning suppressed for struct with single element
+  r = (struct D) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}
 
   return 0;
 }
diff --git a/clang/test/SemaCXX/aggregate-initialization.cpp b/clang/test/SemaCXX/aggregate-initialization.cpp
index 7b6abd2..514473f 100644
--- a/clang/test/SemaCXX/aggregate-initialization.cpp
+++ b/clang/test/SemaCXX/aggregate-initialization.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s 
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s 
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s 
 
 // Verify that using an initializer list for a non-aggregate looks for
 // constructors..
@@ -150,3 +150,33 @@
   // expected-error@-5 {{protected constructor}}
   // expected-note@-30 {{here}}
 }
+
+namespace IdiomaticStdArrayInitDoesNotWarn {
+#pragma clang diagnostic push
+#pragma clang diagnostic warning "-Wmissing-braces"
+  template<typename T, int N> struct StdArray {
+    T contents[N];
+  };
+  StdArray<int, 3> x = {1, 2, 3};
+  
+  template<typename T, int N> struct ArrayAndSomethingElse {
+    T contents[N];
+    int something_else;
+  };
+  ArrayAndSomethingElse<int, 3> y = {1, 2, 3}; // expected-warning {{suggest braces}}
+
+#if __cplusplus >= 201703L
+  template<typename T, int N> struct ArrayAndBaseClass : StdArray<int, 3> {
+    T contents[N];
+  };
+  ArrayAndBaseClass<int, 3> z = {1, 2, 3}; // expected-warning {{suggest braces}}
+
+  // It's not clear whether we should be warning in this case. If this
+  // pattern becomes idiomatic, it would be reasonable to suppress the
+  // warning here too.
+  template<typename T, int N> struct JustABaseClass : StdArray<T, N> {};
+  JustABaseClass<int, 3> w = {1, 2, 3}; // expected-warning {{suggest braces}}
+#endif
+
+#pragma clang diagnostic pop
+}