Emit an extension diagnostic for C99 designated initializers that appear in C++ code

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123582 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 491df7f..f4cc7de 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -56,6 +56,8 @@
   "'new' cannot allocate object of variably modified type %0">;
 
 // C99 Designated Initializers
+def ext_designated_init : Extension<
+  "designated initializers are a C99 feature, accepted in C++ as an extension">;
 def err_array_designator_negative : Error<
   "array designator value '%0' is negative">;
 def err_array_designator_empty_range : Error<
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index e453b0a..23b061d 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -1913,6 +1913,11 @@
                                  Designators.data(), Designators.size(),
                                  InitExpressions.data(), InitExpressions.size(),
                                  Loc, GNUSyntax, Init.takeAs<Expr>());
+  
+  if (getLangOptions().CPlusPlus)
+    Diag(DIE->getLocStart(), diag::ext_designated_init)
+      << DIE->getSourceRange();
+  
   return Owned(DIE);
 }
 
diff --git a/test/SemaCXX/c99.cpp b/test/SemaCXX/c99.cpp
index b0bd45d..cda069c 100644
--- a/test/SemaCXX/c99.cpp
+++ b/test/SemaCXX/c99.cpp
@@ -1,3 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
 void f1(int i[static 5]) { // expected-error{{C99}}
 }
+
+struct Point { int x; int y; };
+
+Point p1 = { .x = 17, // expected-warning{{designated initializers are a C99 feature, accepted in C++ as an extension}} 
+             y: 25 }; // expected-warning{{designated initializers are a C99 feature, accepted in C++ as an extension}} \
+                      // expected-warning{{use of GNU old-style field designator extension}}