Make linkage-specifications hold on to all of their declarations

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61110 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index cce8246..3faf5ac 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -285,6 +285,21 @@
   return new (Mem) OverloadedFunctionDecl(DC, N);
 }
 
+LinkageSpecDecl::LinkageSpecDecl(SourceLocation L, LanguageIDs lang, 
+                                 Decl **InDecls, unsigned InNumDecls)
+  : Decl(LinkageSpec, L), Language(lang), HadBraces(true),
+    Decls(0), NumDecls(InNumDecls) {
+  Decl **NewDecls = new Decl*[NumDecls];
+  for (unsigned I = 0; I < NumDecls; ++I)
+    NewDecls[I] = InDecls[I];
+  Decls = NewDecls;
+}
+
+LinkageSpecDecl::~LinkageSpecDecl() {
+  if (HadBraces)
+    delete [] (Decl**)Decls;
+}
+
 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
                                          SourceLocation L,
                                          LanguageIDs Lang, Decl *D) {
@@ -292,3 +307,20 @@
   return new (Mem) LinkageSpecDecl(L, Lang, D);
 }
 
+LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
+                                         SourceLocation L,
+                                         LanguageIDs Lang, 
+                                         Decl **Decls, unsigned NumDecls) {
+  void *Mem = C.getAllocator().Allocate<LinkageSpecDecl>();
+  return new (Mem) LinkageSpecDecl(L, Lang, Decls, NumDecls);
+}
+
+LinkageSpecDecl::decl_const_iterator LinkageSpecDecl::decls_begin() const {
+  if (hasBraces()) return (Decl**)Decls;
+  else return (Decl**)&Decls;
+}
+
+LinkageSpecDecl::decl_iterator LinkageSpecDecl::decls_end() const {
+  if (hasBraces()) return (Decl**)Decls + NumDecls;
+  else return (Decl**)&Decls + 1;
+}