<div dir="ltr">This p3.cpp test has been failing with MSVC 2013 since it was added:<div><a href="http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9671">http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9671</a><br></div><div><br></div><div>Relatedly, the cxx1z-decomposition.cpp test is failing at HEAD:</div><div><a href="http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9744">http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9744</a><br></div><div><br></div><div>I'll try to repro and get more info.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 11, 2016 at 3:25 PM, Richard Smith via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Thu Aug 11 17:25:46 2016<br>
New Revision: 278435<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278435&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278435&view=rev</a><br>
Log:<br>
P0217R3: Perform semantic checks and initialization for the bindings in a<br>
decomposition declaration for arrays, aggregate-like structs, tuple-like<br>
types, and (as an extension) for complex and vector types.<br>
<br>
Added:<br>
    cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/<br>
    cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p2.cpp<br>
    cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p3.cpp<br>
    cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p4.cpp<br>
Modified:<br>
    cfe/trunk/include/clang/AST/<wbr>CXXInheritance.h<br>
    cfe/trunk/include/clang/AST/<wbr>Decl.h<br>
    cfe/trunk/include/clang/AST/<wbr>DeclCXX.h<br>
    cfe/trunk/include/clang/AST/<wbr>UnresolvedSet.h<br>
    cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
    cfe/trunk/include/clang/Sema/<wbr>Initialization.h<br>
    cfe/trunk/include/clang/Sema/<wbr>Sema.h<br>
    cfe/trunk/lib/AST/ASTDumper.<wbr>cpp<br>
    cfe/trunk/lib/AST/Decl.cpp<br>
    cfe/trunk/lib/AST/DeclCXX.cpp<br>
    cfe/trunk/lib/AST/Expr.cpp<br>
    cfe/trunk/lib/AST/<wbr>ExprClassification.cpp<br>
    cfe/trunk/lib/Sema/Sema.cpp<br>
    cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp<br>
    cfe/trunk/lib/Sema/SemaExpr.<wbr>cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaExprMember.cpp<br>
    cfe/trunk/lib/Sema/SemaInit.<wbr>cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaTemplate.cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaTemplateDeduction.cpp<br>
    cfe/trunk/lib/Sema/SemaType.<wbr>cpp<br>
    cfe/trunk/test/Parser/cxx1z-<wbr>decomposition.cpp<br>
    cfe/trunk/test/SemaCXX/cxx1z-<wbr>decomposition.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/<wbr>CXXInheritance.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CXXInheritance.h?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/AST/CXXInheritance.h?<wbr>rev=278435&r1=278434&r2=<wbr>278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/<wbr>CXXInheritance.h (original)<br>
+++ cfe/trunk/include/clang/AST/<wbr>CXXInheritance.h Thu Aug 11 17:25:46 2016<br>
@@ -172,7 +172,7 @@ public:<br>
   /// paths for a derived-to-base search.<br>
   explicit CXXBasePaths(bool FindAmbiguities = true, bool RecordPaths = true,<br>
                         bool DetectVirtual = true)<br>
-      : FindAmbiguities(<wbr>FindAmbiguities), RecordPaths(RecordPaths),<br>
+      : Origin(), FindAmbiguities(<wbr>FindAmbiguities), RecordPaths(RecordPaths),<br>
         DetectVirtual(DetectVirtual), DetectedVirtual(nullptr),<br>
         NumDeclsFound(0) {}<br>
<br>
<br>
Modified: cfe/trunk/include/clang/AST/<wbr>Decl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/AST/Decl.h?rev=278435&<wbr>r1=278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/<wbr>Decl.h (original)<br>
+++ cfe/trunk/include/clang/AST/<wbr>Decl.h Thu Aug 11 17:25:46 2016<br>
@@ -251,7 +251,7 @@ public:<br>
   // FIXME: Deprecated, move clients to getName().<br>
   std::string getNameAsString() const { return Name.getAsString(); }<br>
<br>
-  void printName(raw_ostream &os) const { os << Name; }<br>
+  virtual void printName(raw_ostream &os) const;<br>
<br>
   /// getDeclName - Get the actual, stored name of the declaration,<br>
   /// which may be a special name.<br>
@@ -1025,7 +1025,7 @@ public:<br>
   ///   void foo() { int x; static int y; extern int z; }<br>
   ///<br>
   bool isLocalVarDecl() const {<br>
-    if (getKind() != Decl::Var)<br>
+    if (getKind() != Decl::Var && getKind() != Decl::Decomposition)<br>
       return false;<br>
     if (const DeclContext *DC = getLexicalDeclContext())<br>
       return DC->getRedeclContext()-><wbr>isFunctionOrMethod();<br>
@@ -1040,7 +1040,7 @@ public:<br>
   /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but<br>
   /// excludes variables declared in blocks.<br>
   bool isFunctionOrMethodVarDecl() const {<br>
-    if (getKind() != Decl::Var)<br>
+    if (getKind() != Decl::Var && getKind() != Decl::Decomposition)<br>
       return false;<br>
     const DeclContext *DC = getLexicalDeclContext()-><wbr>getRedeclContext();<br>
     return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;<br>
<br>
Modified: cfe/trunk/include/clang/AST/<wbr>DeclCXX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/AST/DeclCXX.h?rev=<wbr>278435&r1=278434&r2=278435&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/<wbr>DeclCXX.h (original)<br>
+++ cfe/trunk/include/clang/AST/<wbr>DeclCXX.h Thu Aug 11 17:25:46 2016<br>
@@ -1147,6 +1147,12 @@ public:<br>
   /// \note This does NOT include a check for union-ness.<br>
   bool isEmpty() const { return data().Empty; }<br>
<br>
+  /// \brief Determine whether this class has direct non-static data members.<br>
+  bool hasDirectFields() const {<br>
+    auto &D = data();<br>
+    return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;<br>
+  }<br>
+<br>
   /// Whether this class is polymorphic (C++ [class.virtual]),<br>
   /// which means that the class contains or inherits a virtual function.<br>
   bool isPolymorphic() const { return data().Polymorphic; }<br>
@@ -3451,6 +3457,8 @@ public:<br>
     return llvm::makeArrayRef(<wbr>getTrailingObjects<BindingDecl *>(), NumBindings);<br>
   }<br>
<br>
+  void printName(raw_ostream &os) const override;<br>
+<br>
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }<br>
   static bool classofKind(Kind K) { return K == Decomposition; }<br>
<br>
<br>
Modified: cfe/trunk/include/clang/AST/<wbr>UnresolvedSet.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/UnresolvedSet.h?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/AST/UnresolvedSet.h?rev=<wbr>278435&r1=278434&r2=278435&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/<wbr>UnresolvedSet.h (original)<br>
+++ cfe/trunk/include/clang/AST/<wbr>UnresolvedSet.h Thu Aug 11 17:25:46 2016<br>
@@ -38,7 +38,7 @@ class UnresolvedSetIterator : public llv<br>
       : iterator_adaptor_base(const_<wbr>cast<DeclAccessPair *>(Iter)) {}<br>
<br>
 public:<br>
-  UnresolvedSetIterator() {}<br>
+  UnresolvedSetIterator() = default;<br>
<br>
   NamedDecl *getDecl() const { return I->getDecl(); }<br>
   void setDecl(NamedDecl *ND) const { return I->setDecl(ND); }<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/<wbr>DiagnosticSemaKinds.td?rev=<wbr>278435&r1=278434&r2=278435&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td Thu Aug 11 17:25:46 2016<br>
@@ -385,6 +385,40 @@ def err_decomp_decl_template : Error<<br>
   "decomposition declaration template not supported">;<br>
 def err_decomp_decl_not_alone : Error<<br>
   "decomposition declaration must be the only declaration in its group">;<br>
+def err_decomp_decl_requires_init : Error<<br>
+  "decomposition declaration %0 requires an initializer">;<br>
+def err_decomp_decl_paren_init : Error<<br>
+  "decomposition declaration %0 cannot have a parenthesized initializer">;<br>
+def err_decomp_decl_wrong_number_<wbr>bindings : Error<<br>
+  "type %0 decomposes into %2 elements, but %select{only |}3%1 "<br>
+  "names were provided">;<br>
+def err_decomp_decl_unbindable_<wbr>type : Error<<br>
+  "cannot decompose %select{union|non-class, non-array}1 type %2">;<br>
+def err_decomp_decl_multiple_<wbr>bases_with_members : Error<<br>
+  "cannot decompose class type %1: "<br>
+  "%select{its base classes %2 and|both it and its base class}0 %3 "<br>
+  "have non-static data members">;<br>
+def err_decomp_decl_ambiguous_base : Error<<br>
+  "cannot decompose members of ambiguous base class %1 of %0:%2">;<br>
+def err_decomp_decl_non_public_<wbr>base : Error<<br>
+  "cannot decompose members of non-public base class %1 of %0">;<br>
+def err_decomp_decl_non_public_<wbr>member : Error<<br>
+  "cannot decompose non-public member %0 of %1">;<br>
+def err_decomp_decl_anon_union_<wbr>member : Error<<br>
+  "cannot decompose class type %1 because it has an anonymous "<br>
+  "%select{struct|union} member">;<br>
+def err_decomp_decl_std_tuple_<wbr>element_not_specialized : Error<<br>
+  "cannot decompose this type; 'std::tuple_element<%0>::type' "<br>
+  "does not name a type">;<br>
+def err_decomp_decl_std_tuple_<wbr>size_not_constant : Error<<br>
+  "cannot decompose this type; 'std::tuple_size<%0>::value' "<br>
+  "is not a valid integral constant expression">;<br>
+def note_in_binding_decl_init : Note<<br>
+  "in implicit initialization of binding declaration %0">;<br>
+<br>
+def err_std_type_trait_not_class_<wbr>template : Error<<br>
+  "unsupported standard library implementation: "<br>
+  "'std::%0' is not a class template">;<br>
<br>
 // C++ using declarations<br>
 def err_using_requires_qualname : Error<<br>
<br>
Modified: cfe/trunk/include/clang/Sema/<wbr>Initialization.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Sema/Initialization.h?<wbr>rev=278435&r1=278434&r2=<wbr>278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Sema/<wbr>Initialization.h (original)<br>
+++ cfe/trunk/include/clang/Sema/<wbr>Initialization.h Thu Aug 11 17:25:46 2016<br>
@@ -84,7 +84,10 @@ public:<br>
     EK_RelatedResult,<br>
     /// \brief The entity being initialized is a function parameter; function<br>
     /// is member of group of audited CF APIs.<br>
-    EK_Parameter_CF_Audited<br>
+    EK_Parameter_CF_Audited,<br>
+    /// \brief The entity being initialized is a structured binding of a<br>
+    /// decomposition declaration.<br>
+    EK_Binding,<br>
<br>
     // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this<br>
     // enum as an index for its first %select.  When modifying this list,<br>
@@ -126,9 +129,9 @@ private:<br>
   };<br>
<br>
   union {<br>
-    /// \brief When Kind == EK_Variable, or EK_Member, the VarDecl or<br>
-    /// FieldDecl, respectively.<br>
-    DeclaratorDecl *VariableOrMember;<br>
+    /// \brief When Kind == EK_Variable, EK_Member or EK_Binding, the VarDecl,<br>
+    /// FieldDecl or BindingDecl, respectively.<br>
+    ValueDecl *VariableOrMember;<br>
<br>
     /// \brief When Kind == EK_RelatedResult, the ObjectiveC method where<br>
     /// result type was implicitly changed to accommodate ARC semantics.<br>
@@ -180,6 +183,12 @@ private:<br>
     : Kind(EK_Member), Parent(Parent), Type(Member->getType()),<br>
       ManglingNumber(0), VariableOrMember(Member) { }<br>
<br>
+  /// \brief Create the initialization entity for a binding.<br>
+  InitializedEntity(BindingDecl *Binding, QualType Type,<br>
+                    const InitializedEntity &Parent)<br>
+    : Kind(EK_Binding), Parent(&Parent), Type(Type),<br>
+      ManglingNumber(0), VariableOrMember(Binding) {}<br>
+<br>
   /// \brief Create the initialization entity for an array element.<br>
   InitializedEntity(ASTContext &Context, unsigned Index,<br>
                     const InitializedEntity &Parent);<br>
@@ -314,6 +323,13 @@ public:<br>
     return InitializedEntity(Context, Index, Parent);<br>
   }<br>
<br>
+  /// \brief Create the initialization entity for a structured binding.<br>
+  static InitializedEntity InitializeBinding(const InitializedEntity &Parent,<br>
+                                             BindingDecl *Binding,<br>
+                                             QualType Type) {<br>
+    return InitializedEntity(Binding, Type, Parent);<br>
+  }<br>
+<br>
   /// \brief Create the initialization entity for a lambda capture.<br>
   static InitializedEntity InitializeLambdaCapture(<wbr>IdentifierInfo *VarID,<br>
                                                    QualType FieldType,<br>
@@ -355,7 +371,7 @@ public:<br>
<br>
   /// \brief Retrieve the variable, parameter, or field being<br>
   /// initialized.<br>
-  DeclaratorDecl *getDecl() const;<br>
+  ValueDecl *getDecl() const;<br>
<br>
   /// \brief Retrieve the ObjectiveC method being initialized.<br>
   ObjCMethodDecl *getMethodDecl() const { return MethodDecl; }<br>
<br>
Modified: cfe/trunk/include/clang/Sema/<wbr>Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Sema/Sema.h?rev=278435&<wbr>r1=278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Sema/<wbr>Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/<wbr>Sema.h Thu Aug 11 17:25:46 2016<br>
@@ -1728,7 +1728,9 @@ public:<br>
   // Returns true if the variable declaration is a redeclaration<br>
   bool CheckVariableDeclaration(<wbr>VarDecl *NewVD, LookupResult &Previous);<br>
   void CheckVariableDeclarationType(<wbr>VarDecl *NewVD);<br>
-  void CheckCompleteVariableDeclarati<wbr>on(VarDecl *var);<br>
+  void CheckCompleteVariableDeclarati<wbr>on(VarDecl *VD, InitializedEntity &Entity);<br>
+  void CheckCompleteDecompositionDecl<wbr>aration(DecompositionDecl *DD,<br>
+                                             InitializedEntity &Entity);<br>
   void MaybeSuggestAddingStaticToDecl<wbr>(const FunctionDecl *D);<br>
<br>
   NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,<br>
@@ -3970,6 +3972,12 @@ public:<br>
                            bool SuppressQualifierCheck = false,<br>
                            ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);<br>
<br>
+  ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,<br>
+                                     SourceLocation OpLoc,<br>
+                                     const CXXScopeSpec &SS, FieldDecl *Field,<br>
+                                     DeclAccessPair FoundDecl,<br>
+                                     const DeclarationNameInfo &MemberNameInfo);<br>
+<br>
   ExprResult PerformMemberExprBaseConversio<wbr>n(Expr *Base, bool IsArrow);<br>
<br>
   bool CheckQualifiedMemberReference(<wbr>Expr *BaseExpr, QualType BaseType,<br>
@@ -5772,6 +5780,10 @@ public:<br>
                             TemplateParameterList **OuterTemplateParamLists,<br>
                                 SkipBodyInfo *SkipBody = nullptr);<br>
<br>
+  TemplateArgumentLoc getTrivialTemplateArgumentLoc(<wbr>const TemplateArgument &Arg,<br>
+                                                    QualType NTTPType,<br>
+                                                    SourceLocation Loc);<br>
+<br>
   void translateTemplateArguments(<wbr>const ASTTemplateArgsPtr &In,<br>
                                   TemplateArgumentListInfo &Out);<br>
<br>
<br>
Modified: cfe/trunk/lib/AST/ASTDumper.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>ASTDumper.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/AST/ASTDumper.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTDumper.<wbr>cpp Thu Aug 11 17:25:46 2016<br>
@@ -429,6 +429,7 @@ namespace  {<br>
     void VisitFieldDecl(const FieldDecl *D);<br>
     void VisitVarDecl(const VarDecl *D);<br>
     void VisitDecompositionDecl(const DecompositionDecl *D);<br>
+    void VisitBindingDecl(const BindingDecl *D);<br>
     void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);<br>
     void VisitImportDecl(const ImportDecl *D);<br>
     void VisitPragmaCommentDecl(const PragmaCommentDecl *D);<br>
@@ -1224,6 +1225,13 @@ void ASTDumper::<wbr>VisitDecompositionDecl(c<br>
     dumpDecl(B);<br>
 }<br>
<br>
+void ASTDumper::VisitBindingDecl(<wbr>const BindingDecl *D) {<br>
+  dumpName(D);<br>
+  dumpType(D->getType());<br>
+  if (auto *E = D->getBinding())<br>
+    dumpStmt(E);<br>
+}<br>
+<br>
 void ASTDumper::<wbr>VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {<br>
   dumpStmt(D->getAsmString());<br>
 }<br>
<br>
Modified: cfe/trunk/lib/AST/Decl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>Decl.cpp?rev=278435&r1=278434&<wbr>r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/AST/Decl.cpp (original)<br>
+++ cfe/trunk/lib/AST/Decl.cpp Thu Aug 11 17:25:46 2016<br>
@@ -1395,6 +1395,10 @@ static LinkageInfo getLVForDecl(const Na<br>
   return clang::LinkageComputer::<wbr>getLVForDecl(D, computation);<br>
 }<br>
<br>
+void NamedDecl::printName(raw_<wbr>ostream &os) const {<br>
+  os << Name;<br>
+}<br>
+<br>
 std::string NamedDecl::<wbr>getQualifiedNameAsString() const {<br>
   std::string QualName;<br>
   llvm::raw_string_ostream OS(QualName);<br>
@@ -1481,7 +1485,7 @@ void NamedDecl::printQualifiedName(<wbr>raw_o<br>
     OS << "::";<br>
   }<br>
<br>
-  if (getDeclName())<br>
+  if (getDeclName() || isa<DecompositionDecl>(this))<br>
     OS << *this;<br>
   else<br>
     OS << "(anonymous)";<br>
<br>
Modified: cfe/trunk/lib/AST/DeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>DeclCXX.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Aug 11 17:25:46 2016<br>
@@ -2344,6 +2344,18 @@ DecompositionDecl *DecompositionDecl::Cr<br>
   return Result;<br>
 }<br>
<br>
+void DecompositionDecl::printName(<wbr>llvm::raw_ostream &os) const {<br>
+  os << '[';<br>
+  bool Comma = false;<br>
+  for (auto *B : bindings()) {<br>
+    if (Comma)<br>
+      os << ", ";<br>
+    B->printName(os);<br>
+    Comma = true;<br>
+  }<br>
+  os << ']';<br>
+}<br>
+<br>
 MSPropertyDecl *MSPropertyDecl::Create(<wbr>ASTContext &C, DeclContext *DC,<br>
                                        SourceLocation L, DeclarationName N,<br>
                                        QualType T, TypeSourceInfo *TInfo,<br>
<br>
Modified: cfe/trunk/lib/AST/Expr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>Expr.cpp?rev=278435&r1=278434&<wbr>r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/AST/Expr.cpp (original)<br>
+++ cfe/trunk/lib/AST/Expr.cpp Thu Aug 11 17:25:46 2016<br>
@@ -3308,11 +3308,16 @@ FieldDecl *Expr::getSourceBitField() {<br>
       if (Ivar->isBitField())<br>
         return Ivar;<br>
<br>
-  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E))<br>
+  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) {<br>
     if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef-><wbr>getDecl()))<br>
       if (Field->isBitField())<br>
         return Field;<br>
<br>
+    if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef-<wbr>>getDecl()))<br>
+      if (Expr *E = BD->getBinding())<br>
+        return E->getSourceBitField();<br>
+  }<br>
+<br>
   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) {<br>
     if (BinOp->isAssignmentOp() && BinOp->getLHS())<br>
       return BinOp->getLHS()-><wbr>getSourceBitField();<br>
@@ -3329,6 +3334,7 @@ FieldDecl *Expr::getSourceBitField() {<br>
 }<br>
<br>
 bool Expr::refersToVectorElement() const {<br>
+  // FIXME: Why do we not just look at the ObjectKind here?<br>
   const Expr *E = this->IgnoreParens();<br>
<br>
   while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {<br>
@@ -3345,6 +3351,11 @@ bool Expr::refersToVectorElement() const<br>
   if (isa<ExtVectorElementExpr>(E))<br>
     return true;<br>
<br>
+  if (auto *DRE = dyn_cast<DeclRefExpr>(E))<br>
+    if (auto *BD = dyn_cast<BindingDecl>(DRE-><wbr>getDecl()))<br>
+      if (auto *E = BD->getBinding())<br>
+        return E->refersToVectorElement();<br>
+<br>
   return false;<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/AST/<wbr>ExprClassification.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>ExprClassification.cpp?rev=<wbr>278435&r1=278434&r2=278435&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/AST/<wbr>ExprClassification.cpp (original)<br>
+++ cfe/trunk/lib/AST/<wbr>ExprClassification.cpp Thu Aug 11 17:25:46 2016<br>
@@ -429,6 +429,7 @@ static Cl::Kinds ClassifyDecl(ASTContext<br>
   else<br>
     islvalue = isa<VarDecl>(D) || isa<FieldDecl>(D) ||<br>
                isa<IndirectFieldDecl>(D) ||<br>
+               isa<BindingDecl>(D) ||<br>
                (Ctx.getLangOpts().CPlusPlus &&<br>
                 (isa<FunctionDecl>(D) || isa<MSPropertyDecl>(D) ||<br>
                  isa<FunctionTemplateDecl>(D)))<wbr>;<br>
<br>
Modified: cfe/trunk/lib/Sema/Sema.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>Sema.cpp?rev=278435&r1=278434&<wbr>r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/Sema.cpp (original)<br>
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Aug 11 17:25:46 2016<br>
@@ -28,6 +28,7 @@<br>
 #include "clang/Sema/CXXFieldCollector.<wbr>h"<br>
 #include "clang/Sema/DelayedDiagnostic.<wbr>h"<br>
 #include "clang/Sema/<wbr>ExternalSemaSource.h"<br>
+#include "clang/Sema/Initialization.h"<br>
 #include "clang/Sema/<wbr>MultiplexExternalSemaSource.h"<br>
 #include "clang/Sema/ObjCMethodList.h"<br>
 #include "clang/Sema/<wbr>PrettyDeclStackTrace.h"<br>
@@ -809,7 +810,9 @@ void Sema::<wbr>ActOnEndOfTranslationUnit() {<br>
                                    diag::err_tentative_def_<wbr>incomplete_type))<br>
       VD->setInvalidDecl();<br>
<br>
-    CheckCompleteVariableDeclarati<wbr>on(VD);<br>
+    // No initialization is performed for a tentative definition.<br>
+    InitializedEntity Entity = InitializedEntity::<wbr>InitializeVariable(VD);<br>
+    CheckCompleteVariableDeclarati<wbr>on(VD, Entity);<br>
<br>
     // Notify the consumer that we've completed a tentative definition.<br>
     if (!VD->isInvalidDecl())<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDecl.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp Thu Aug 11 17:25:46 2016<br>
@@ -43,7 +43,6 @@<br>
 #include "clang/Sema/SemaInternal.h"<br>
 #include "clang/Sema/Template.h"<br>
 #include "llvm/ADT/SmallString.h"<br>
-#include "llvm/ADT/StringExtras.h"<br>
 #include "llvm/ADT/Triple.h"<br>
 #include <algorithm><br>
 #include <cstring><br>
@@ -6534,157 +6533,6 @@ NamedDecl *Sema::ActOnVariableDeclarator<br>
   return NewVD;<br>
 }<br>
<br>
-NamedDecl *<br>
-Sema::<wbr>ActOnDecompositionDeclarator(<wbr>Scope *S, Declarator &D,<br>
-                                   MultiTemplateParamsArg TemplateParamLists) {<br>
-  assert(D.<wbr>isDecompositionDeclarator());<br>
-  const DecompositionDeclarator &Decomp = D.getDecompositionDeclarator()<wbr>;<br>
-<br>
-  // The syntax only allows a decomposition declarator as a simple-declaration<br>
-  // or a for-range-declaration, but we parse it in more cases than that.<br>
-  if (!D.<wbr>mayHaveDecompositionDeclarator<wbr>()) {<br>
-    Diag(Decomp.getLSquareLoc(), diag::err_decomp_decl_context)<br>
-      << Decomp.getSourceRange();<br>
-    return nullptr;<br>
-  }<br>
-<br>
-  if (!TemplateParamLists.empty()) {<br>
-    // FIXME: There's no rule against this, but there are also no rules that<br>
-    // would actually make it usable, so we reject it for now.<br>
-    Diag(TemplateParamLists.front(<wbr>)->getTemplateLoc(),<br>
-         diag::err_decomp_decl_<wbr>template);<br>
-    return nullptr;<br>
-  }<br>
-<br>
-  Diag(Decomp.getLSquareLoc(), getLangOpts().CPlusPlus1z<br>
-                                   ? diag::warn_cxx14_compat_<wbr>decomp_decl<br>
-                                   : diag::ext_decomp_decl)<br>
-      << Decomp.getSourceRange();<br>
-<br>
-  // The semantic context is always just the current context.<br>
-  DeclContext *const DC = CurContext;<br>
-<br>
-  // C++1z [dcl.dcl]/8:<br>
-  //   The decl-specifier-seq shall contain only the type-specifier auto<br>
-  //   and cv-qualifiers.<br>
-  auto &DS = D.getDeclSpec();<br>
-  {<br>
-    SmallVector<StringRef, 8> BadSpecifiers;<br>
-    SmallVector<SourceLocation, 8> BadSpecifierLocs;<br>
-    if (auto SCS = DS.getStorageClassSpec()) {<br>
-      BadSpecifiers.push_back(<wbr>DeclSpec::getSpecifierName(<wbr>SCS));<br>
-      BadSpecifierLocs.push_back(DS.<wbr>getStorageClassSpecLoc());<br>
-    }<br>
-    if (auto TSCS = DS.getThreadStorageClassSpec()<wbr>) {<br>
-      BadSpecifiers.push_back(<wbr>DeclSpec::getSpecifierName(<wbr>TSCS));<br>
-      BadSpecifierLocs.push_back(DS.<wbr>getThreadStorageClassSpecLoc()<wbr>);<br>
-    }<br>
-    if (DS.isConstexprSpecified()) {<br>
-      BadSpecifiers.push_back("<wbr>constexpr");<br>
-      BadSpecifierLocs.push_back(DS.<wbr>getConstexprSpecLoc());<br>
-    }<br>
-    if (DS.isInlineSpecified()) {<br>
-      BadSpecifiers.push_back("<wbr>inline");<br>
-      BadSpecifierLocs.push_back(DS.<wbr>getInlineSpecLoc());<br>
-    }<br>
-    if (!BadSpecifiers.empty()) {<br>
-      auto &&Err = Diag(BadSpecifierLocs.front(), diag::err_decomp_decl_spec);<br>
-      Err << (int)BadSpecifiers.size()<br>
-          << llvm::join(BadSpecifiers.<wbr>begin(), BadSpecifiers.end(), " ");<br>
-      // Don't add FixItHints to remove the specifiers; we do still respect<br>
-      // them when building the underlying variable.<br>
-      for (auto Loc : BadSpecifierLocs)<br>
-        Err << SourceRange(Loc, Loc);<br>
-    }<br>
-    // We can't recover from it being declared as a typedef.<br>
-    if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef)<br>
-      return nullptr;<br>
-  }<br>
-<br>
-  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);<br>
-  QualType R = TInfo->getType();<br>
-<br>
-  if (<wbr>DiagnoseUnexpandedParameterPac<wbr>k(D.getIdentifierLoc(), TInfo,<br>
-                                      UPPC_DeclarationType))<br>
-    D.setInvalidType();<br>
-<br>
-  // The syntax only allows a single ref-qualifier prior to the decomposition<br>
-  // declarator. No other declarator chunks are permitted. Also check the type<br>
-  // specifier here.<br>
-  if (DS.getTypeSpecType() != DeclSpec::TST_auto ||<br>
-      D.hasGroupingParens() || D.getNumTypeObjects() > 1 ||<br>
-      (D.getNumTypeObjects() == 1 &&<br>
-       D.getTypeObject(0).Kind != DeclaratorChunk::Reference)) {<br>
-    Diag(Decomp.getLSquareLoc(),<br>
-         (D.hasGroupingParens() ||<br>
-          (D.getNumTypeObjects() &&<br>
-           D.getTypeObject(0).Kind == DeclaratorChunk::Paren))<br>
-             ? diag::err_decomp_decl_parens<br>
-             : diag::err_decomp_decl_type)<br>
-        << R;<br>
-<br>
-    // In most cases, there's no actual problem with an explicitly-specified<br>
-    // type, but a function type won't work here, and ActOnVariableDeclarator<br>
-    // shouldn't be called for such a type.<br>
-    if (R->isFunctionType())<br>
-      D.setInvalidType();<br>
-  }<br>
-<br>
-  // Build the BindingDecls.<br>
-  SmallVector<BindingDecl*, 8> Bindings;<br>
-<br>
-  // Build the BindingDecls.<br>
-  for (auto &B : D.getDecompositionDeclarator()<wbr>.bindings()) {<br>
-    // Check for name conflicts.<br>
-    DeclarationNameInfo NameInfo(B.Name, B.NameLoc);<br>
-    LookupResult Previous(*this, NameInfo, LookupOrdinaryName,<br>
-                          ForRedeclaration);<br>
-    LookupName(Previous, S,<br>
-               /*CreateBuiltins*/DC-><wbr>getRedeclContext()-><wbr>isTranslationUnit());<br>
-<br>
-    // It's not permitted to shadow a template parameter name.<br>
-    if (Previous.isSingleResult() &&<br>
-        Previous.getFoundDecl()-><wbr>isTemplateParameter()) {<br>
-      DiagnoseTemplateParameterShado<wbr>w(D.getIdentifierLoc(),<br>
-                                      Previous.getFoundDecl());<br>
-      Previous.clear();<br>
-    }<br>
-<br>
-    bool ConsiderLinkage = DC->isFunctionOrMethod() &&<br>
-                           DS.getStorageClassSpec() == DeclSpec::SCS_extern;<br>
-    FilterLookupForScope(Previous, DC, S, ConsiderLinkage,<br>
-                         /*AllowInlineNamespace*/false)<wbr>;<br>
-    if (!Previous.empty()) {<br>
-      auto *Old = Previous.<wbr>getRepresentativeDecl();<br>
-      Diag(B.NameLoc, diag::err_redefinition) << B.Name;<br>
-      Diag(Old->getLocation(), diag::note_previous_<wbr>definition);<br>
-    }<br>
-<br>
-    auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name);<br>
-    PushOnScopeChains(BD, S, true);<br>
-    Bindings.push_back(BD);<br>
-    ParsingInitForAutoVars.insert(<wbr>BD);<br>
-  }<br>
-<br>
-  // There are no prior lookup results for the variable itself, because it<br>
-  // is unnamed.<br>
-  DeclarationNameInfo NameInfo((IdentifierInfo *)nullptr,<br>
-                               Decomp.getLSquareLoc());<br>
-  LookupResult Previous(*this, NameInfo, LookupOrdinaryName, ForRedeclaration);<br>
-<br>
-  // Build the variable that holds the non-decomposed object.<br>
-  bool AddToScope = true;<br>
-  NamedDecl *New =<br>
-      ActOnVariableDeclarator(S, D, DC, TInfo, Previous,<br>
-                              MultiTemplateParamsArg(), AddToScope, Bindings);<br>
-  CurContext->addHiddenDecl(New)<wbr>;<br>
-<br>
-  if (<wbr>isInOpenMPDeclareTargetContext<wbr>())<br>
-    checkDeclIsAllowedInOpenMPTarg<wbr>et(nullptr, New);<br>
-<br>
-  return New;<br>
-}<br>
-<br>
 /// Enum describing the %select options in diag::warn_decl_shadow.<br>
 enum ShadowedDeclKind { SDK_Local, SDK_Global, SDK_StaticMember, SDK_Field };<br>
<br>
@@ -9604,6 +9452,9 @@ QualType Sema::<wbr>deduceVarTypeFromInitiali<br>
   assert((!VDecl || !VDecl->isInitCapture()) &&<br>
          "init captures are expected to be deduced prior to initialization");<br>
<br>
+  // FIXME: Deduction for a decomposition declaration does weird things if the<br>
+  // initializer is an array.<br>
+<br>
   ArrayRef<Expr *> DeduceInits = Init;<br>
   if (DirectInit) {<br>
     if (auto *PL = dyn_cast<ParenListExpr>(Init))<br>
@@ -9713,6 +9564,11 @@ void Sema::AddInitializerToDecl(<wbr>Decl *Re<br>
     return;<br>
   }<br>
<br>
+  // C++1z [dcl.dcl]p1 grammar implies that a parenthesized initializer is not<br>
+  // permitted.<br>
+  if (isa<DecompositionDecl>(VDecl) && DirectInit && isa<ParenListExpr>(Init))<br>
+    Diag(VDecl->getLocation(), diag::err_decomp_decl_paren_<wbr>init) << VDecl;<br>
+<br>
   // C++11 [decl.spec.auto]p6. Deduce the type which 'auto' stands in for.<br>
   if (TypeMayContainAuto && VDecl->getType()-><wbr>isUndeducedType()) {<br>
     // Attempt typo correction early so that the type of the init expression can<br>
@@ -9864,8 +9720,8 @@ void Sema::AddInitializerToDecl(<wbr>Decl *Re<br>
<br>
   // Perform the initialization.<br>
   ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);<br>
+  InitializedEntity Entity = InitializedEntity::<wbr>InitializeVariable(VDecl);<br>
   if (!VDecl->isInvalidDecl()) {<br>
-    InitializedEntity Entity = InitializedEntity::<wbr>InitializeVariable(VDecl);<br>
     InitializationKind Kind =<br>
         DirectInit<br>
             ? CXXDirectInit<br>
@@ -10116,7 +9972,7 @@ void Sema::AddInitializerToDecl(<wbr>Decl *Re<br>
     VDecl->setInitStyle(VarDecl::<wbr>ListInit);<br>
   }<br>
<br>
-  CheckCompleteVariableDeclarati<wbr>on(VDecl);<br>
+  CheckCompleteVariableDeclarati<wbr>on(VDecl, Entity);<br>
 }<br>
<br>
 /// ActOnInitializerError - Given that there was an error parsing an<br>
@@ -10173,6 +10029,13 @@ void Sema::ActOnUninitializedDecl(<wbr>Decl *<br>
   if (VarDecl *Var = dyn_cast<VarDecl>(RealDecl)) {<br>
     QualType Type = Var->getType();<br>
<br>
+    // C++1z [dcl.dcl]p1 grammar implies that an initializer is mandatory.<br>
+    if (isa<DecompositionDecl>(<wbr>RealDecl)) {<br>
+      Diag(Var->getLocation(), diag::err_decomp_decl_<wbr>requires_init) << Var;<br>
+      Var->setInvalidDecl();<br>
+      return;<br>
+    }<br>
+<br>
     // C++11 [dcl.spec.auto]p3<br>
     if (TypeMayContainAuto && Type->getContainedAutoType()) {<br>
       Diag(Var->getLocation(), diag::err_auto_var_requires_<wbr>init)<br>
@@ -10394,7 +10257,7 @@ void Sema::ActOnUninitializedDecl(<wbr>Decl *<br>
       Var->setInitStyle(VarDecl::<wbr>CallInit);<br>
     }<br>
<br>
-    CheckCompleteVariableDeclarati<wbr>on(Var);<br>
+    CheckCompleteVariableDeclarati<wbr>on(Var, Entity);<br>
   }<br>
 }<br>
<br>
@@ -10471,7 +10334,8 @@ Sema::<wbr>ActOnCXXForRangeIdentifier(<wbr>Scope *<br>
                        AttrEnd.isValid() ? AttrEnd : IdentLoc);<br>
 }<br>
<br>
-void Sema::<wbr>CheckCompleteVariableDeclarati<wbr>on(VarDecl *var) {<br>
+void Sema::<wbr>CheckCompleteVariableDeclarati<wbr>on(VarDecl *var,<br>
+                                            InitializedEntity &Entity) {<br>
   if (var->isInvalidDecl()) return;<br>
<br>
   if (getLangOpts().OpenCL) {<br>
@@ -10580,6 +10444,9 @@ void Sema::<wbr>CheckCompleteVariableDeclarat<br>
   // All the following checks are C++ only.<br>
   if (!getLangOpts().CPlusPlus) return;<br>
<br>
+  if (auto *DD = dyn_cast<DecompositionDecl>(<wbr>var))<br>
+    CheckCompleteDecompositionDecl<wbr>aration(DD, Entity);<br>
+<br>
   QualType type = var->getType();<br>
   if (type->isDependentType()) return;<br>
<br>
@@ -10680,9 +10547,13 @@ Sema::FinalizeDeclaration(Decl *ThisDecl<br>
   if (!VD)<br>
     return;<br>
<br>
-  if (auto *DD = dyn_cast<DecompositionDecl>(<wbr>ThisDecl))<br>
-    for (auto *BD : DD->bindings())<br>
+  if (auto *DD = dyn_cast<DecompositionDecl>(<wbr>ThisDecl)) {<br>
+    for (auto *BD : DD->bindings()) {<br>
+      if (ThisDecl->isInvalidDecl())<br>
+        BD->setInvalidDecl();<br>
       FinalizeDeclaration(BD);<br>
+    }<br>
+  }<br>
<br>
   checkAttributesAfterMerging(*<wbr>this, *VD);<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp Thu Aug 11 17:25:46 2016<br>
@@ -39,6 +39,7 @@<br>
 #include "clang/Sema/Template.h"<br>
 #include "llvm/ADT/STLExtras.h"<br>
 #include "llvm/ADT/SmallString.h"<br>
+#include "llvm/ADT/StringExtras.h"<br>
 #include <map><br>
 #include <set><br>
<br>
@@ -664,6 +665,753 @@ bool Sema::MergeCXXFunctionDecl(<wbr>Function<br>
   return Invalid;<br>
 }<br>
<br>
+NamedDecl *<br>
+Sema::<wbr>ActOnDecompositionDeclarator(<wbr>Scope *S, Declarator &D,<br>
+                                   MultiTemplateParamsArg TemplateParamLists) {<br>
+  assert(D.<wbr>isDecompositionDeclarator());<br>
+  const DecompositionDeclarator &Decomp = D.getDecompositionDeclarator()<wbr>;<br>
+<br>
+  // The syntax only allows a decomposition declarator as a simple-declaration<br>
+  // or a for-range-declaration, but we parse it in more cases than that.<br>
+  if (!D.<wbr>mayHaveDecompositionDeclarator<wbr>()) {<br>
+    Diag(Decomp.getLSquareLoc(), diag::err_decomp_decl_context)<br>
+      << Decomp.getSourceRange();<br>
+    return nullptr;<br>
+  }<br>
+<br>
+  if (!TemplateParamLists.empty()) {<br>
+    // FIXME: There's no rule against this, but there are also no rules that<br>
+    // would actually make it usable, so we reject it for now.<br>
+    Diag(TemplateParamLists.front(<wbr>)->getTemplateLoc(),<br>
+         diag::err_decomp_decl_<wbr>template);<br>
+    return nullptr;<br>
+  }<br>
+<br>
+  Diag(Decomp.getLSquareLoc(), getLangOpts().CPlusPlus1z<br>
+                                   ? diag::warn_cxx14_compat_<wbr>decomp_decl<br>
+                                   : diag::ext_decomp_decl)<br>
+      << Decomp.getSourceRange();<br>
+<br>
+  // The semantic context is always just the current context.<br>
+  DeclContext *const DC = CurContext;<br>
+<br>
+  // C++1z [dcl.dcl]/8:<br>
+  //   The decl-specifier-seq shall contain only the type-specifier auto<br>
+  //   and cv-qualifiers.<br>
+  auto &DS = D.getDeclSpec();<br>
+  {<br>
+    SmallVector<StringRef, 8> BadSpecifiers;<br>
+    SmallVector<SourceLocation, 8> BadSpecifierLocs;<br>
+    if (auto SCS = DS.getStorageClassSpec()) {<br>
+      BadSpecifiers.push_back(<wbr>DeclSpec::getSpecifierName(<wbr>SCS));<br>
+      BadSpecifierLocs.push_back(DS.<wbr>getStorageClassSpecLoc());<br>
+    }<br>
+    if (auto TSCS = DS.getThreadStorageClassSpec()<wbr>) {<br>
+      BadSpecifiers.push_back(<wbr>DeclSpec::getSpecifierName(<wbr>TSCS));<br>
+      BadSpecifierLocs.push_back(DS.<wbr>getThreadStorageClassSpecLoc()<wbr>);<br>
+    }<br>
+    if (DS.isConstexprSpecified()) {<br>
+      BadSpecifiers.push_back("<wbr>constexpr");<br>
+      BadSpecifierLocs.push_back(DS.<wbr>getConstexprSpecLoc());<br>
+    }<br>
+    if (DS.isInlineSpecified()) {<br>
+      BadSpecifiers.push_back("<wbr>inline");<br>
+      BadSpecifierLocs.push_back(DS.<wbr>getInlineSpecLoc());<br>
+    }<br>
+    if (!BadSpecifiers.empty()) {<br>
+      auto &&Err = Diag(BadSpecifierLocs.front(), diag::err_decomp_decl_spec);<br>
+      Err << (int)BadSpecifiers.size()<br>
+          << llvm::join(BadSpecifiers.<wbr>begin(), BadSpecifiers.end(), " ");<br>
+      // Don't add FixItHints to remove the specifiers; we do still respect<br>
+      // them when building the underlying variable.<br>
+      for (auto Loc : BadSpecifierLocs)<br>
+        Err << SourceRange(Loc, Loc);<br>
+    }<br>
+    // We can't recover from it being declared as a typedef.<br>
+    if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef)<br>
+      return nullptr;<br>
+  }<br>
+<br>
+  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);<br>
+  QualType R = TInfo->getType();<br>
+<br>
+  if (<wbr>DiagnoseUnexpandedParameterPac<wbr>k(D.getIdentifierLoc(), TInfo,<br>
+                                      UPPC_DeclarationType))<br>
+    D.setInvalidType();<br>
+<br>
+  // The syntax only allows a single ref-qualifier prior to the decomposition<br>
+  // declarator. No other declarator chunks are permitted. Also check the type<br>
+  // specifier here.<br>
+  if (DS.getTypeSpecType() != DeclSpec::TST_auto ||<br>
+      D.hasGroupingParens() || D.getNumTypeObjects() > 1 ||<br>
+      (D.getNumTypeObjects() == 1 &&<br>
+       D.getTypeObject(0).Kind != DeclaratorChunk::Reference)) {<br>
+    Diag(Decomp.getLSquareLoc(),<br>
+         (D.hasGroupingParens() ||<br>
+          (D.getNumTypeObjects() &&<br>
+           D.getTypeObject(0).Kind == DeclaratorChunk::Paren))<br>
+             ? diag::err_decomp_decl_parens<br>
+             : diag::err_decomp_decl_type)<br>
+        << R;<br>
+<br>
+    // In most cases, there's no actual problem with an explicitly-specified<br>
+    // type, but a function type won't work here, and ActOnVariableDeclarator<br>
+    // shouldn't be called for such a type.<br>
+    if (R->isFunctionType())<br>
+      D.setInvalidType();<br>
+  }<br>
+<br>
+  // Build the BindingDecls.<br>
+  SmallVector<BindingDecl*, 8> Bindings;<br>
+<br>
+  // Build the BindingDecls.<br>
+  for (auto &B : D.getDecompositionDeclarator()<wbr>.bindings()) {<br>
+    // Check for name conflicts.<br>
+    DeclarationNameInfo NameInfo(B.Name, B.NameLoc);<br>
+    LookupResult Previous(*this, NameInfo, LookupOrdinaryName,<br>
+                          ForRedeclaration);<br>
+    LookupName(Previous, S,<br>
+               /*CreateBuiltins*/DC-><wbr>getRedeclContext()-><wbr>isTranslationUnit());<br>
+<br>
+    // It's not permitted to shadow a template parameter name.<br>
+    if (Previous.isSingleResult() &&<br>
+        Previous.getFoundDecl()-><wbr>isTemplateParameter()) {<br>
+      DiagnoseTemplateParameterShado<wbr>w(D.getIdentifierLoc(),<br>
+                                      Previous.getFoundDecl());<br>
+      Previous.clear();<br>
+    }<br>
+<br>
+    bool ConsiderLinkage = DC->isFunctionOrMethod() &&<br>
+                           DS.getStorageClassSpec() == DeclSpec::SCS_extern;<br>
+    FilterLookupForScope(Previous, DC, S, ConsiderLinkage,<br>
+                         /*AllowInlineNamespace*/false)<wbr>;<br>
+    if (!Previous.empty()) {<br>
+      auto *Old = Previous.<wbr>getRepresentativeDecl();<br>
+      Diag(B.NameLoc, diag::err_redefinition) << B.Name;<br>
+      Diag(Old->getLocation(), diag::note_previous_<wbr>definition);<br>
+    }<br>
+<br>
+    auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name);<br>
+    PushOnScopeChains(BD, S, true);<br>
+    Bindings.push_back(BD);<br>
+    ParsingInitForAutoVars.insert(<wbr>BD);<br>
+  }<br>
+<br>
+  // There are no prior lookup results for the variable itself, because it<br>
+  // is unnamed.<br>
+  DeclarationNameInfo NameInfo((IdentifierInfo *)nullptr,<br>
+                               Decomp.getLSquareLoc());<br>
+  LookupResult Previous(*this, NameInfo, LookupOrdinaryName, ForRedeclaration);<br>
+<br>
+  // Build the variable that holds the non-decomposed object.<br>
+  bool AddToScope = true;<br>
+  NamedDecl *New =<br>
+      ActOnVariableDeclarator(S, D, DC, TInfo, Previous,<br>
+                              MultiTemplateParamsArg(), AddToScope, Bindings);<br>
+  CurContext->addHiddenDecl(New)<wbr>;<br>
+<br>
+  if (<wbr>isInOpenMPDeclareTargetContext<wbr>())<br>
+    checkDeclIsAllowedInOpenMPTarg<wbr>et(nullptr, New);<br>
+<br>
+  return New;<br>
+}<br>
+<br>
+static bool checkSimpleDecomposition(<br>
+    Sema &S, ArrayRef<BindingDecl *> Bindings, ValueDecl *Src,<br>
+    QualType DecompType, llvm::APSInt NumElems, QualType ElemType,<br>
+    llvm::function_ref<ExprResult(<wbr>SourceLocation, Expr *, unsigned)> GetInit) {<br>
+  if ((int64_t)Bindings.size() != NumElems) {<br>
+    S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_<wbr>number_bindings)<br>
+        << DecompType << (unsigned)Bindings.size() << NumElems.toString(10)<br>
+        << (NumElems < Bindings.size());<br>
+    return true;<br>
+  }<br>
+<br>
+  unsigned I = 0;<br>
+  for (auto *B : Bindings) {<br>
+    SourceLocation Loc = B->getLocation();<br>
+    ExprResult E = S.BuildDeclRefExpr(Src, DecompType, VK_LValue, Loc);<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+    E = GetInit(Loc, E.get(), I++);<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+    B->setBinding(ElemType, E.get());<br>
+  }<br>
+<br>
+  return false;<br>
+}<br>
+<br>
+static bool checkArrayLikeDecomposition(<wbr>Sema &S,<br>
+                                        ArrayRef<BindingDecl *> Bindings,<br>
+                                        ValueDecl *Src, QualType DecompType,<br>
+                                        llvm::APSInt NumElems,<br>
+                                        QualType ElemType) {<br>
+  return checkSimpleDecomposition(<br>
+      S, Bindings, Src, DecompType, NumElems, ElemType,<br>
+      [&](SourceLocation Loc, Expr *Base, unsigned I) -> ExprResult {<br>
+        ExprResult E = S.ActOnIntegerConstant(Loc, I);<br>
+        if (E.isInvalid())<br>
+          return ExprError();<br>
+        return S.<wbr>CreateBuiltinArraySubscriptExp<wbr>r(Base, Loc, E.get(), Loc);<br>
+      });<br>
+}<br>
+<br>
+static bool checkArrayDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,<br>
+                                    ValueDecl *Src, QualType DecompType,<br>
+                                    const ConstantArrayType *CAT) {<br>
+  return checkArrayLikeDecomposition(S, Bindings, Src, DecompType,<br>
+                                     llvm::APSInt(CAT->getSize()),<br>
+                                     CAT->getElementType());<br>
+}<br>
+<br>
+static bool checkVectorDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,<br>
+                                     ValueDecl *Src, QualType DecompType,<br>
+                                     const VectorType *VT) {<br>
+  return checkArrayLikeDecomposition(<br>
+      S, Bindings, Src, DecompType, llvm::APSInt::get(VT-><wbr>getNumElements()),<br>
+      S.Context.getQualifiedType(VT-<wbr>>getElementType(),<br>
+                                 DecompType.getQualifiers()));<br>
+}<br>
+<br>
+static bool checkComplexDecomposition(Sema &S,<br>
+                                      ArrayRef<BindingDecl *> Bindings,<br>
+                                      ValueDecl *Src, QualType DecompType,<br>
+                                      const ComplexType *CT) {<br>
+  return checkSimpleDecomposition(<br>
+      S, Bindings, Src, DecompType, llvm::APSInt::get(2),<br>
+      S.Context.getQualifiedType(CT-<wbr>>getElementType(),<br>
+                                 DecompType.getQualifiers()),<br>
+      [&](SourceLocation Loc, Expr *Base, unsigned I) -> ExprResult {<br>
+        return S.CreateBuiltinUnaryOp(Loc, I ? UO_Imag : UO_Real, Base);<br>
+      });<br>
+}<br>
+<br>
+static std::string printTemplateArgs(const PrintingPolicy &PrintingPolicy,<br>
+                                     TemplateArgumentListInfo &Args) {<br>
+  SmallString<128> SS;<br>
+  llvm::raw_svector_ostream OS(SS);<br>
+  bool First = true;<br>
+  for (auto &Arg : Args.arguments()) {<br>
+    if (!First)<br>
+      OS << ", ";<br>
+    Arg.getArgument().print(<wbr>PrintingPolicy, OS);<br>
+    First = false;<br>
+  }<br>
+  return OS.str();<br>
+}<br>
+<br>
+static bool lookupStdTypeTraitMember(Sema &S, LookupResult &TraitMemberLookup,<br>
+                                     SourceLocation Loc, StringRef Trait,<br>
+                                     TemplateArgumentListInfo &Args,<br>
+                                     unsigned DiagID) {<br>
+  auto DiagnoseMissing = [&] {<br>
+    if (DiagID)<br>
+      S.Diag(Loc, DiagID) << printTemplateArgs(S.Context.<wbr>getPrintingPolicy(),<br>
+                                               Args);<br>
+    return true;<br>
+  };<br>
+<br>
+  // FIXME: Factor out duplication with lookupPromiseType in SemaCoroutine.<br>
+  NamespaceDecl *Std = S.getStdNamespace();<br>
+  if (!Std)<br>
+    return DiagnoseMissing();<br>
+<br>
+  // Look up the trait itself, within namespace std. We can diagnose various<br>
+  // problems with this lookup even if we've been asked to not diagnose a<br>
+  // missing specialization, because this can only fail if the user has been<br>
+  // declaring their own names in namespace std or we don't support the<br>
+  // standard library implementation in use.<br>
+  LookupResult Result(S, &S.PP.getIdentifierTable().<wbr>get(Trait),<br>
+                      Loc, Sema::LookupOrdinaryName);<br>
+  if (!S.LookupQualifiedName(<wbr>Result, Std))<br>
+    return DiagnoseMissing();<br>
+  if (Result.isAmbiguous())<br>
+    return true;<br>
+<br>
+  ClassTemplateDecl *TraitTD = Result.getAsSingle<<wbr>ClassTemplateDecl>();<br>
+  if (!TraitTD) {<br>
+    Result.suppressDiagnostics();<br>
+    NamedDecl *Found = *Result.begin();<br>
+    S.Diag(Loc, diag::err_std_type_trait_not_<wbr>class_template) << Trait;<br>
+    S.Diag(Found->getLocation(), diag::note_declared_at);<br>
+    return true;<br>
+  }<br>
+<br>
+  // Build the template-id.<br>
+  QualType TraitTy = S.CheckTemplateIdType(<wbr>TemplateName(TraitTD), Loc, Args);<br>
+  if (TraitTy.isNull())<br>
+    return true;<br>
+  if (!S.isCompleteType(Loc, TraitTy)) {<br>
+    if (DiagID)<br>
+      S.RequireCompleteType(<br>
+          Loc, TraitTy, DiagID,<br>
+          printTemplateArgs(S.Context.<wbr>getPrintingPolicy(), Args));<br>
+    return true;<br>
+  }<br>
+<br>
+  CXXRecordDecl *RD = TraitTy->getAsCXXRecordDecl();<br>
+  assert(RD && "specialization of class template is not a class?");<br>
+<br>
+  // Look up the member of the trait type.<br>
+  S.LookupQualifiedName(<wbr>TraitMemberLookup, RD);<br>
+  return TraitMemberLookup.isAmbiguous(<wbr>);<br>
+}<br>
+<br>
+static TemplateArgumentLoc<br>
+<wbr>getTrivialIntegralTemplateArgu<wbr>ment(Sema &S, SourceLocation Loc, QualType T,<br>
+                                   uint64_t I) {<br>
+  TemplateArgument Arg(S.Context, S.Context.MakeIntValue(I, T), T);<br>
+  return S.<wbr>getTrivialTemplateArgumentLoc(<wbr>Arg, T, Loc);<br>
+}<br>
+<br>
+static TemplateArgumentLoc<br>
+<wbr>getTrivialTypeTemplateArgument<wbr>(Sema &S, SourceLocation Loc, QualType T) {<br>
+  return S.<wbr>getTrivialTemplateArgumentLoc(<wbr>TemplateArgument(T), QualType(), Loc);<br>
+}<br>
+<br>
+namespace { enum class IsTupleLike { TupleLike, NotTupleLike, Error }; }<br>
+<br>
+static IsTupleLike isTupleLike(Sema &S, SourceLocation Loc, QualType T,<br>
+                               llvm::APSInt &Size) {<br>
+  EnterExpressionEvaluationConte<wbr>xt ContextRAII(S, Sema::ConstantEvaluated);<br>
+<br>
+  DeclarationName Value = S.PP.getIdentifierInfo("value"<wbr>);<br>
+  LookupResult R(S, Value, Loc, Sema::LookupOrdinaryName);<br>
+<br>
+  // Form template argument list for tuple_size<T>.<br>
+  TemplateArgumentListInfo Args(Loc, Loc);<br>
+  Args.addArgument(<wbr>getTrivialTypeTemplateArgument<wbr>(S, Loc, T));<br>
+<br>
+  // If there's no tuple_size specialization, it's not tuple-like.<br>
+  if (lookupStdTypeTraitMember(S, R, Loc, "tuple_size", Args, /*DiagID*/0))<br>
+    return IsTupleLike::NotTupleLike;<br>
+<br>
+  // FIXME: According to the standard, we're not supposed to diagnose if any<br>
+  // of the steps below fail (or if lookup for ::value is ambiguous or otherwise<br>
+  // results in an error), but this is subject to a pending CWG issue / NB<br>
+  // comment, which says we do diagnose if tuple_size<T> is complete but<br>
+  // tuple_size<T>::value is not an ICE.<br>
+<br>
+  struct ICEDiagnoser : Sema::VerifyICEDiagnoser {<br>
+    LookupResult &R;<br>
+    TemplateArgumentListInfo &Args;<br>
+    ICEDiagnoser(LookupResult &R, TemplateArgumentListInfo &Args)<br>
+        : R(R), Args(Args) {}<br>
+    void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) {<br>
+      S.Diag(Loc, diag::err_decomp_decl_std_<wbr>tuple_size_not_constant)<br>
+          << printTemplateArgs(S.Context.<wbr>getPrintingPolicy(), Args);<br>
+    }<br>
+  } Diagnoser(R, Args);<br>
+<br>
+  if (R.empty()) {<br>
+    Diagnoser.diagnoseNotICE(S, Loc, SourceRange());<br>
+    return IsTupleLike::Error;<br>
+  }<br>
+<br>
+  ExprResult E =<br>
+      S.BuildDeclarationNameExpr(<wbr>CXXScopeSpec(), R, /*NeedsADL*/false);<br>
+  if (E.isInvalid())<br>
+    return IsTupleLike::Error;<br>
+<br>
+  E = S.<wbr>VerifyIntegerConstantExpressio<wbr>n(E.get(), &Size, Diagnoser, false);<br>
+  if (E.isInvalid())<br>
+    return IsTupleLike::Error;<br>
+<br>
+  return IsTupleLike::TupleLike;<br>
+}<br>
+<br>
+/// \return std::tuple_element<I, T>::type.<br>
+static QualType getTupleLikeElementType(Sema &S, SourceLocation Loc,<br>
+                                        unsigned I, QualType T) {<br>
+  // Form template argument list for tuple_element<I, T>.<br>
+  TemplateArgumentListInfo Args(Loc, Loc);<br>
+  Args.addArgument(<br>
+      getTrivialIntegralTemplateArgu<wbr>ment(S, Loc, S.Context.getSizeType(), I));<br>
+  Args.addArgument(<wbr>getTrivialTypeTemplateArgument<wbr>(S, Loc, T));<br>
+<br>
+  DeclarationName TypeDN = S.PP.getIdentifierInfo("type")<wbr>;<br>
+  LookupResult R(S, TypeDN, Loc, Sema::LookupOrdinaryName);<br>
+  if (lookupStdTypeTraitMember(<br>
+          S, R, Loc, "tuple_element", Args,<br>
+          diag::err_decomp_decl_std_<wbr>tuple_element_not_specialized)<wbr>)<br>
+    return QualType();<br>
+<br>
+  auto *TD = R.getAsSingle<TypeDecl>();<br>
+  if (!TD) {<br>
+    R.suppressDiagnostics();<br>
+    S.Diag(Loc, diag::err_decomp_decl_std_<wbr>tuple_element_not_specialized)<br>
+      << printTemplateArgs(S.Context.<wbr>getPrintingPolicy(), Args);<br>
+    if (!R.empty())<br>
+      S.Diag(R.<wbr>getRepresentativeDecl()-><wbr>getLocation(), diag::note_declared_at);<br>
+    return QualType();<br>
+  }<br>
+<br>
+  return S.Context.getTypeDeclType(TD);<br>
+}<br>
+<br>
+namespace {<br>
+struct BindingDiagnosticTrap {<br>
+  Sema &S;<br>
+  DiagnosticErrorTrap Trap;<br>
+  BindingDecl *BD;<br>
+<br>
+  BindingDiagnosticTrap(Sema &S, BindingDecl *BD)<br>
+      : S(S), Trap(S.Diags), BD(BD) {}<br>
+  ~BindingDiagnosticTrap() {<br>
+    if (Trap.hasErrorOccurred())<br>
+      S.Diag(BD->getLocation(), diag::note_in_binding_decl_<wbr>init) << BD;<br>
+  }<br>
+};<br>
+}<br>
+<br>
+static bool<br>
+checkTupleLikeDecomposition(<wbr>Sema &S, ArrayRef<BindingDecl *> Bindings,<br>
+                            ValueDecl *Src, InitializedEntity &ParentEntity,<br>
+                            QualType DecompType, llvm::APSInt TupleSize) {<br>
+  if ((int64_t)Bindings.size() != TupleSize) {<br>
+    S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_<wbr>number_bindings)<br>
+        << DecompType << (unsigned)Bindings.size() << TupleSize.toString(10)<br>
+        << (TupleSize < Bindings.size());<br>
+    return true;<br>
+  }<br>
+<br>
+  if (Bindings.empty())<br>
+    return false;<br>
+<br>
+  DeclarationName GetDN = S.PP.getIdentifierInfo("get");<br>
+<br>
+  // [dcl.decomp]p3:<br>
+  //   The unqualified-id get is looked up in the scope of E by class member<br>
+  //   access lookup<br>
+  LookupResult MemberGet(S, GetDN, Src->getLocation(), Sema::LookupMemberName);<br>
+  bool UseMemberGet = false;<br>
+  if (S.isCompleteType(Src-><wbr>getLocation(), DecompType)) {<br>
+    if (auto *RD = DecompType-><wbr>getAsCXXRecordDecl())<br>
+      S.LookupQualifiedName(<wbr>MemberGet, RD);<br>
+    if (MemberGet.isAmbiguous())<br>
+      return true;<br>
+    UseMemberGet = !MemberGet.empty();<br>
+    S.<wbr>FilterAcceptableTemplateNames(<wbr>MemberGet);<br>
+  }<br>
+<br>
+  unsigned I = 0;<br>
+  for (auto *B : Bindings) {<br>
+    BindingDiagnosticTrap Trap(S, B);<br>
+    SourceLocation Loc = B->getLocation();<br>
+<br>
+    ExprResult E = S.BuildDeclRefExpr(Src, DecompType, VK_LValue, Loc);<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+<br>
+    //   e is an lvalue if the type of the entity is an lvalue reference and<br>
+    //   an xvalue otherwise<br>
+    if (!Src->getType()-><wbr>isLValueReferenceType())<br>
+      E = ImplicitCastExpr::Create(S.<wbr>Context, E.get()->getType(), CK_NoOp,<br>
+                                   E.get(), nullptr, VK_XValue);<br>
+<br>
+    TemplateArgumentListInfo Args(Loc, Loc);<br>
+    Args.addArgument(<br>
+        getTrivialIntegralTemplateArgu<wbr>ment(S, Loc, S.Context.getSizeType(), I));<br>
+<br>
+    if (UseMemberGet) {<br>
+      //   if [lookup of member get] finds at least one declaration, the<br>
+      //   initializer is e.get<i-1>().<br>
+      E = S.BuildMemberReferenceExpr(E.<wbr>get(), DecompType, Loc, false,<br>
+                                     CXXScopeSpec(), SourceLocation(), nullptr,<br>
+                                     MemberGet, &Args, nullptr);<br>
+      if (E.isInvalid())<br>
+        return true;<br>
+<br>
+      E = S.ActOnCallExpr(nullptr, E.get(), Loc, None, Loc);<br>
+    } else {<br>
+      //   Otherwise, the initializer is get<i-1>(e), where get is looked up<br>
+      //   in the associated namespaces.<br>
+      Expr *Get = UnresolvedLookupExpr::Create(<br>
+          S.Context, nullptr, NestedNameSpecifierLoc(), SourceLocation(),<br>
+          DeclarationNameInfo(GetDN, Loc), /*RequiresADL*/true, &Args,<br>
+          UnresolvedSetIterator(), UnresolvedSetIterator());<br>
+<br>
+      Expr *Arg = E.get();<br>
+      E = S.ActOnCallExpr(nullptr, Get, Loc, Arg, Loc);<br>
+    }<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+    Expr *Init = E.get();<br>
+<br>
+    //   Given the type T designated by std::tuple_element<i - 1, E>::type,<br>
+    QualType T = getTupleLikeElementType(S, Loc, I, DecompType);<br>
+    if (T.isNull())<br>
+      return true;<br>
+<br>
+    //   each vi is a variable of type "reference to T" initialized with the<br>
+    //   initializer, where the reference is an lvalue reference if the<br>
+    //   initializer is an lvalue and an rvalue reference otherwise<br>
+    QualType RefType =<br>
+        S.BuildReferenceType(T, E.get()->isLValue(), Loc, B->getDeclName());<br>
+    if (RefType.isNull())<br>
+      return true;<br>
+<br>
+    InitializedEntity Entity =<br>
+        InitializedEntity::<wbr>InitializeBinding(<wbr>ParentEntity, B, RefType);<br>
+    InitializationKind Kind = InitializationKind::<wbr>CreateCopy(Loc, Loc);<br>
+    InitializationSequence Seq(S, Entity, Kind, Init);<br>
+    E = Seq.Perform(S, Entity, Kind, Init);<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+<br>
+    B->setBinding(T, E.get());<br>
+    I++;<br>
+  }<br>
+<br>
+  return false;<br>
+}<br>
+<br>
+/// Find the base class to decompose in a built-in decomposition of a class type.<br>
+/// This base class search is, unfortunately, not quite like any other that we<br>
+/// perform anywhere else in C++.<br>
+static const CXXRecordDecl *findDecomposableBaseClass(<wbr>Sema &S,<br>
+                                                      SourceLocation Loc,<br>
+                                                      const CXXRecordDecl *RD,<br>
+                                                      CXXCastPath &BasePath) {<br>
+  auto BaseHasFields = [](const CXXBaseSpecifier *Specifier,<br>
+                          CXXBasePath &Path) {<br>
+    return Specifier->getType()-><wbr>getAsCXXRecordDecl()-><wbr>hasDirectFields();<br>
+  };<br>
+<br>
+  const CXXRecordDecl *ClassWithFields = nullptr;<br>
+  if (RD->hasDirectFields())<br>
+    // [dcl.decomp]p4:<br>
+    //   Otherwise, all of E's non-static data members shall be public direct<br>
+    //   members of E ...<br>
+    ClassWithFields = RD;<br>
+  else {<br>
+    //   ... or of ...<br>
+    CXXBasePaths Paths;<br>
+    Paths.setOrigin(const_cast<<wbr>CXXRecordDecl*>(RD));<br>
+    if (!RD->lookupInBases(<wbr>BaseHasFields, Paths)) {<br>
+      // If no classes have fields, just decompose RD itself. (This will work<br>
+      // if and only if zero bindings were provided.)<br>
+      return RD;<br>
+    }<br>
+<br>
+    CXXBasePath *BestPath = nullptr;<br>
+    for (auto &P : Paths) {<br>
+      if (!BestPath)<br>
+        BestPath = &P;<br>
+      else if (!S.Context.hasSameType(P.<wbr>back().Base->getType(),<br>
+                                      BestPath->back().Base-><wbr>getType())) {<br>
+        //   ... the same ...<br>
+        S.Diag(Loc, diag::err_decomp_decl_<wbr>multiple_bases_with_members)<br>
+          << false << RD << BestPath->back().Base-><wbr>getType()<br>
+          << P.back().Base->getType();<br>
+        return nullptr;<br>
+      } else if (P.Access < BestPath->Access) {<br>
+        BestPath = &P;<br>
+      }<br>
+    }<br>
+<br>
+    //   ... unambiguous ...<br>
+    QualType BaseType = BestPath->back().Base-><wbr>getType();<br>
+    if (Paths.isAmbiguous(S.Context.<wbr>getCanonicalType(BaseType))) {<br>
+      S.Diag(Loc, diag::err_decomp_decl_<wbr>ambiguous_base)<br>
+        << RD << BaseType << S.<wbr>getAmbiguousPathsDisplayString<wbr>(Paths);<br>
+      return nullptr;<br>
+    }<br>
+<br>
+    //   ... public base class of E.<br>
+    if (BestPath->Access != AS_public) {<br>
+      S.Diag(Loc, diag::err_decomp_decl_non_<wbr>public_base)<br>
+        << RD << BaseType;<br>
+      for (auto &BS : *BestPath) {<br>
+        if (BS.Base->getAccessSpecifier() != AS_public) {<br>
+          S.Diag(BS.Base->getLocStart(), diag::note_access_constrained_<wbr>by_path)<br>
+            << (BS.Base->getAccessSpecifier() == AS_protected)<br>
+            << (BS.Base-><wbr>getAccessSpecifierAsWritten() == AS_none);<br>
+          break;<br>
+        }<br>
+      }<br>
+      return nullptr;<br>
+    }<br>
+<br>
+    ClassWithFields = BaseType->getAsCXXRecordDecl()<wbr>;<br>
+    S.BuildBasePathArray(Paths, BasePath);<br>
+  }<br>
+<br>
+  // The above search did not check whether the selected class itself has base<br>
+  // classes with fields, so check that now.<br>
+  CXXBasePaths Paths;<br>
+  if (ClassWithFields-><wbr>lookupInBases(BaseHasFields, Paths)) {<br>
+    S.Diag(Loc, diag::err_decomp_decl_<wbr>multiple_bases_with_members)<br>
+      << (ClassWithFields == RD) << RD << ClassWithFields<br>
+      << Paths.front().back().Base-><wbr>getType();<br>
+    return nullptr;<br>
+  }<br>
+<br>
+  return ClassWithFields;<br>
+}<br>
+<br>
+static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,<br>
+                                     ValueDecl *Src, QualType DecompType,<br>
+                                     const CXXRecordDecl *RD) {<br>
+  CXXCastPath BasePath;<br>
+  RD = findDecomposableBaseClass(S, Src->getLocation(), RD, BasePath);<br>
+  if (!RD)<br>
+    return true;<br>
+  QualType BaseType = S.Context.getQualifiedType(S.<wbr>Context.getRecordType(RD),<br>
+                                                 DecompType.getQualifiers());<br>
+<br>
+  auto DiagnoseBadNumberOfBindings = [&]() -> bool {<br>
+    unsigned NumFields = std::distance(RD->field_begin(<wbr>), RD->field_end());<br>
+    assert(Bindings.size() != NumFields);<br>
+    S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_<wbr>number_bindings)<br>
+        << DecompType << (unsigned)Bindings.size() << NumFields<br>
+        << (NumFields < Bindings.size());<br>
+    return true;<br>
+  };<br>
+<br>
+  //   all of E's non-static data members shall be public [...] members,<br>
+  //   E shall not have an anonymous union member, ...<br>
+  unsigned I = 0;<br>
+  for (auto *FD : RD->fields()) {<br>
+    if (FD->isUnnamedBitfield())<br>
+      continue;<br>
+<br>
+    if (FD->isAnonymousStructOrUnion(<wbr>)) {<br>
+      S.Diag(Src->getLocation(), diag::err_decomp_decl_anon_<wbr>union_member)<br>
+        << DecompType << FD->getType()->isUnionType();<br>
+      S.Diag(FD->getLocation(), diag::note_declared_at);<br>
+      return true;<br>
+    }<br>
+<br>
+    // We have a real field to bind.<br>
+    if (I >= Bindings.size())<br>
+      return DiagnoseBadNumberOfBindings();<br>
+    auto *B = Bindings[I++];<br>
+<br>
+    SourceLocation Loc = B->getLocation();<br>
+    if (FD->getAccess() != AS_public) {<br>
+      S.Diag(Loc, diag::err_decomp_decl_non_<wbr>public_member) << FD << DecompType;<br>
+<br>
+      // Determine whether the access specifier was explicit.<br>
+      bool Implicit = true;<br>
+      for (const auto *D : RD->decls()) {<br>
+        if (declaresSameEntity(D, FD))<br>
+          break;<br>
+        if (isa<AccessSpecDecl>(D)) {<br>
+          Implicit = false;<br>
+          break;<br>
+        }<br>
+      }<br>
+<br>
+      S.Diag(FD->getLocation(), diag::note_access_natural)<br>
+        << (FD->getAccess() == AS_protected) << Implicit;<br>
+      return true;<br>
+    }<br>
+<br>
+    // Initialize the binding to Src.FD.<br>
+    ExprResult E = S.BuildDeclRefExpr(Src, DecompType, VK_LValue, Loc);<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+    E = S.ImpCastExprToType(E.get(), BaseType, CK_UncheckedDerivedToBase,<br>
+                            VK_LValue, &BasePath);<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+    E = S.BuildFieldReferenceExpr(E.<wbr>get(), /*IsArrow*/ false, Loc,<br>
+                                  CXXScopeSpec(), FD,<br>
+                                  DeclAccessPair::make(FD, FD->getAccess()),<br>
+                                  DeclarationNameInfo(FD-><wbr>getDeclName(), Loc));<br>
+    if (E.isInvalid())<br>
+      return true;<br>
+<br>
+    // If the type of the member is T, the referenced type is cv T, where cv is<br>
+    // the cv-qualification of the decomposition expression.<br>
+    //<br>
+    // FIXME: We resolve a defect here: if the field is mutable, we do not add<br>
+    // 'const' to the type of the field.<br>
+    Qualifiers Q = DecompType.getQualifiers();<br>
+    if (FD->isMutable())<br>
+      Q.removeConst();<br>
+    B->setBinding(S.<wbr>BuildQualifiedType(FD-><wbr>getType(), Loc, Q), E.get());<br>
+  }<br>
+<br>
+  if (I != Bindings.size())<br>
+    return DiagnoseBadNumberOfBindings();<br>
+<br>
+  return false;<br>
+}<br>
+<br>
+void Sema::<wbr>CheckCompleteDecompositionDecl<wbr>aration(DecompositionDecl *DD,<br>
+                                                 InitializedEntity &Entity) {<br>
+  QualType DecompType = DD->getType();<br>
+<br>
+  // If the type of the decomposition is dependent, then so is the type of<br>
+  // each binding.<br>
+  if (DecompType->isDependentType()<wbr>) {<br>
+    for (auto *B : DD->bindings())<br>
+      B->setType(Context.<wbr>DependentTy);<br>
+    return;<br>
+  }<br>
+<br>
+  DecompType = DecompType.<wbr>getNonReferenceType();<br>
+  ArrayRef<BindingDecl*> Bindings = DD->bindings();<br>
+<br>
+  // C++1z [dcl.decomp]/2:<br>
+  //   If E is an array type [...]<br>
+  // As an extension, we also support decomposition of built-in complex and<br>
+  // vector types.<br>
+  if (auto *CAT = Context.<wbr>getAsConstantArrayType(<wbr>DecompType)) {<br>
+    if (checkArrayDecomposition(*<wbr>this, Bindings, DD, DecompType, CAT))<br>
+      DD->setInvalidDecl();<br>
+    return;<br>
+  }<br>
+  if (auto *VT = DecompType->getAs<VectorType>(<wbr>)) {<br>
+    if (checkVectorDecomposition(*<wbr>this, Bindings, DD, DecompType, VT))<br>
+      DD->setInvalidDecl();<br>
+    return;<br>
+  }<br>
+  if (auto *CT = DecompType->getAs<ComplexType><wbr>()) {<br>
+    if (checkComplexDecomposition(*<wbr>this, Bindings, DD, DecompType, CT))<br>
+      DD->setInvalidDecl();<br>
+    return;<br>
+  }<br>
+<br>
+  // C++1z [dcl.decomp]/3:<br>
+  //   if the expression std::tuple_size<E>::value is a well-formed integral<br>
+  //   constant expression, [...]<br>
+  llvm::APSInt TupleSize(32);<br>
+  switch (isTupleLike(*this, DD->getLocation(), DecompType, TupleSize)) {<br>
+  case IsTupleLike::Error:<br>
+    DD->setInvalidDecl();<br>
+    return;<br>
+<br>
+  case IsTupleLike::TupleLike:<br>
+    if (checkTupleLikeDecomposition(*<wbr>this, Bindings, DD, Entity, DecompType,<br>
+                                    TupleSize))<br>
+      DD->setInvalidDecl();<br>
+    return;<br>
+<br>
+  case IsTupleLike::NotTupleLike:<br>
+    break;<br>
+  }<br>
+<br>
+  // C++1z [dcl.dcl]/8:<br>
+  //   [E shall be of array or non-union class type]<br>
+  CXXRecordDecl *RD = DecompType-><wbr>getAsCXXRecordDecl();<br>
+  if (!RD || RD->isUnion()) {<br>
+    Diag(DD->getLocation(), diag::err_decomp_decl_<wbr>unbindable_type)<br>
+        << DD << !RD << DecompType;<br>
+    DD->setInvalidDecl();<br>
+    return;<br>
+  }<br>
+<br>
+  // C++1z [dcl.decomp]/4:<br>
+  //   all of E's non-static data members shall be [...] direct members of<br>
+  //   E or of the same unambiguous public base class of E, ...<br>
+  if (checkMemberDecomposition(*<wbr>this, Bindings, DD, DecompType, RD))<br>
+    DD->setInvalidDecl();<br>
+}<br>
+<br>
 /// \brief Merge the exception specifications of two variable declarations.<br>
 ///<br>
 /// This is called when there's a redeclaration of a VarDecl. The function<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaExpr.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaExpr.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.<wbr>cpp Thu Aug 11 17:25:46 2016<br>
@@ -1788,6 +1788,12 @@ Sema::BuildDeclRefExpr(<wbr>ValueDecl *D, Qua<br>
       E->setObjectKind(OK_BitField);<br>
   }<br>
<br>
+  // C++ [expr.prim]/8: The expression [...] is a bit-field if the identifier<br>
+  // designates a bit-field.<br>
+  if (auto *BD = dyn_cast<BindingDecl>(D))<br>
+    if (auto *BE = BD->getBinding())<br>
+      E->setObjectKind(BE-><wbr>getObjectKind());<br>
+<br>
   return E;<br>
 }<br>
<br>
@@ -2943,7 +2949,6 @@ ExprResult Sema::BuildDeclarationNameExp<br>
     case Decl::<wbr>VarTemplateSpecialization:<br>
     case Decl::<wbr>VarTemplatePartialSpecializati<wbr>on:<br>
     case Decl::Decomposition:<br>
-    case Decl::Binding:<br>
     case Decl::OMPCapturedExpr:<br>
       // In C, "extern void blah;" is valid and is an r-value.<br>
       if (!getLangOpts().CPlusPlus &&<br>
@@ -2971,6 +2976,14 @@ ExprResult Sema::BuildDeclarationNameExp<br>
<br>
       break;<br>
     }<br>
+<br>
+    case Decl::Binding: {<br>
+      // These are always lvalues.<br>
+      valueKind = VK_LValue;<br>
+      type = type.getNonReferenceType();<br>
+      // FIXME: Adjust cv-qualifiers for capture.<br>
+      break;<br>
+    }<br>
<br>
     case Decl::Function: {<br>
       if (unsigned BID = cast<FunctionDecl>(VD)-><wbr>getBuiltinID()) {<br>
@@ -10580,7 +10593,8 @@ QualType Sema::CheckAddressOfOperand(<wbr>Exp<br>
           return MPTy;<br>
         }<br>
       }<br>
-    } else if (!isa<FunctionDecl>(dcl) && !isa<NonTypeTemplateParmDecl>(<wbr>dcl))<br>
+    } else if (!isa<FunctionDecl>(dcl) && !isa<NonTypeTemplateParmDecl>(<wbr>dcl) &&<br>
+               !isa<BindingDecl>(dcl))<br>
       llvm_unreachable("Unknown/<wbr>unexpected decl type");<br>
   }<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaExprMember.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaExprMember.cpp?rev=278435&<wbr>r1=278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaExprMember.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaExprMember.cpp Thu Aug 11 17:25:46 2016<br>
@@ -771,12 +771,6 @@ Sema::<wbr>BuildMemberReferenceExpr(Expr *Bas<br>
                                   false, ExtraArgs);<br>
 }<br>
<br>
-static ExprResult<br>
-BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,<br>
-                        SourceLocation OpLoc, const CXXScopeSpec &SS,<br>
-                        FieldDecl *Field, DeclAccessPair FoundDecl,<br>
-                        const DeclarationNameInfo &MemberNameInfo);<br>
-<br>
 ExprResult<br>
 Sema::<wbr>BuildAnonymousStructUnionMembe<wbr>rReference(const CXXScopeSpec &SS,<br>
                                                SourceLocation loc,<br>
@@ -862,7 +856,7 @@ Sema::<wbr>BuildAnonymousStructUnionMembe<wbr>rRef<br>
     // Make a nameInfo that properly uses the anonymous name.<br>
     DeclarationNameInfo memberNameInfo(field-><wbr>getDeclName(), loc);<br>
<br>
-    result = BuildFieldReferenceExpr(*this, result, baseObjectIsPointer,<br>
+    result = BuildFieldReferenceExpr(<wbr>result, baseObjectIsPointer,<br>
                                      SourceLocation(), EmptySS, field,<br>
                                      foundDecl, memberNameInfo).get();<br>
     if (!result)<br>
@@ -883,9 +877,10 @@ Sema::<wbr>BuildAnonymousStructUnionMembe<wbr>rRef<br>
         DeclAccessPair::make(field, field->getAccess());<br>
<br>
     result =<br>
-        BuildFieldReferenceExpr(*this, result, /*isarrow*/ false,<br>
-                                SourceLocation(), (FI == FEnd ? SS : EmptySS),<br>
-                                field, fakeFoundDecl, memberNameInfo).get();<br>
+        BuildFieldReferenceExpr(<wbr>result, /*isarrow*/ false, SourceLocation(),<br>
+                                (FI == FEnd ? SS : EmptySS), field,<br>
+                                fakeFoundDecl, memberNameInfo)<br>
+            .get();<br>
   }<br>
<br>
   return result;<br>
@@ -1153,8 +1148,8 @@ Sema::<wbr>BuildMemberReferenceExpr(Expr *Bas<br>
     return ExprError();<br>
<br>
   if (FieldDecl *FD = dyn_cast<FieldDecl>(<wbr>MemberDecl))<br>
-    return BuildFieldReferenceExpr(*this, BaseExpr, IsArrow, OpLoc, SS, FD,<br>
-                                   FoundDecl, MemberNameInfo);<br>
+    return BuildFieldReferenceExpr(<wbr>BaseExpr, IsArrow, OpLoc, SS, FD, FoundDecl,<br>
+                                   MemberNameInfo);<br>
<br>
   if (MSPropertyDecl *PD = dyn_cast<MSPropertyDecl>(<wbr>MemberDecl))<br>
     return BuildMSPropertyRefExpr(*this, BaseExpr, IsArrow, SS, PD,<br>
@@ -1757,11 +1752,11 @@ ExprResult Sema::ActOnMemberAccessExpr(S<br>
                                   NameInfo, TemplateArgs, S, &ExtraArgs);<br>
 }<br>
<br>
-static ExprResult<br>
-BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,<br>
-                        SourceLocation OpLoc, const CXXScopeSpec &SS,<br>
-                        FieldDecl *Field, DeclAccessPair FoundDecl,<br>
-                        const DeclarationNameInfo &MemberNameInfo) {<br>
+ExprResult<br>
+Sema::<wbr>BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,<br>
+                              SourceLocation OpLoc, const CXXScopeSpec &SS,<br>
+                              FieldDecl *Field, DeclAccessPair FoundDecl,<br>
+                              const DeclarationNameInfo &MemberNameInfo) {<br>
   // x.a is an l-value if 'a' has a reference type. Otherwise:<br>
   // x.a is an l-value/x-value/pr-value if the base is (and note<br>
   //   that *x is always an l-value), except that if the base isn't<br>
@@ -1795,36 +1790,34 @@ BuildFieldReferenceExpr(Sema &S, Expr *B<br>
     // except that 'mutable' members don't pick up 'const'.<br>
     if (Field->isMutable()) BaseQuals.removeConst();<br>
<br>
-    Qualifiers MemberQuals<br>
-    = S.Context.getCanonicalType(<wbr>MemberType).getQualifiers();<br>
+    Qualifiers MemberQuals =<br>
+        Context.getCanonicalType(<wbr>MemberType).getQualifiers();<br>
<br>
     assert(!MemberQuals.<wbr>hasAddressSpace());<br>
<br>
-<br>
     Qualifiers Combined = BaseQuals + MemberQuals;<br>
     if (Combined != MemberQuals)<br>
-      MemberType = S.Context.getQualifiedType(<wbr>MemberType, Combined);<br>
+      MemberType = Context.getQualifiedType(<wbr>MemberType, Combined);<br>
   }<br>
<br>
-  S.UnusedPrivateFields.remove(<wbr>Field);<br>
+  UnusedPrivateFields.remove(<wbr>Field);<br>
<br>
-  ExprResult Base =<br>
-  S.<wbr>PerformObjectMemberConversion(<wbr>BaseExpr, SS.getScopeRep(),<br>
-                                  FoundDecl, Field);<br>
+  ExprResult Base = PerformObjectMemberConversion(<wbr>BaseExpr, SS.getScopeRep(),<br>
+                                                  FoundDecl, Field);<br>
   if (Base.isInvalid())<br>
     return ExprError();<br>
   MemberExpr *ME =<br>
-      BuildMemberExpr(S, S.Context, Base.get(), IsArrow, OpLoc, SS,<br>
+      BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS,<br>
                       /*TemplateKWLoc=*/<wbr>SourceLocation(), Field, FoundDecl,<br>
                       MemberNameInfo, MemberType, VK, OK);<br>
<br>
   // Build a reference to a private copy for non-static data members in<br>
   // non-static member functions, privatized by OpenMP constructs.<br>
-  if (S.getLangOpts().OpenMP && IsArrow &&<br>
-      !S.CurContext-><wbr>isDependentContext() &&<br>
+  if (getLangOpts().OpenMP && IsArrow &&<br>
+      !CurContext-><wbr>isDependentContext() &&<br>
       isa<CXXThisExpr>(Base.get()-><wbr>IgnoreParenImpCasts())) {<br>
-    if (auto *PrivateCopy = S.IsOpenMPCapturedDecl(Field))<br>
-      return S.getOpenMPCapturedExpr(<wbr>PrivateCopy, VK, OK, OpLoc);<br>
+    if (auto *PrivateCopy = IsOpenMPCapturedDecl(Field))<br>
+      return getOpenMPCapturedExpr(<wbr>PrivateCopy, VK, OK, OpLoc);<br>
   }<br>
   return ME;<br>
 }<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaInit.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaInit.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaInit.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaInit.<wbr>cpp Thu Aug 11 17:25:46 2016<br>
@@ -936,6 +936,7 @@ static void warnBracedScalarInit(Sema &S<br>
   case InitializedEntity::EK_Base:<br>
   case InitializedEntity::EK_<wbr>Delegating:<br>
   case InitializedEntity::EK_<wbr>BlockElement:<br>
+  case InitializedEntity::EK_Binding:<br>
     llvm_unreachable("unexpected braced scalar init");<br>
   }<br>
<br>
@@ -2895,6 +2896,7 @@ DeclarationName InitializedEntity::getNa<br>
<br>
   case EK_Variable:<br>
   case EK_Member:<br>
+  case EK_Binding:<br>
     return VariableOrMember->getDeclName(<wbr>);<br>
<br>
   case EK_LambdaCapture:<br>
@@ -2918,10 +2920,11 @@ DeclarationName InitializedEntity::getNa<br>
   llvm_unreachable("Invalid EntityKind!");<br>
 }<br>
<br>
-DeclaratorDecl *InitializedEntity::getDecl() const {<br>
+ValueDecl *InitializedEntity::getDecl() const {<br>
   switch (getKind()) {<br>
   case EK_Variable:<br>
   case EK_Member:<br>
+  case EK_Binding:<br>
     return VariableOrMember;<br>
<br>
   case EK_Parameter:<br>
@@ -2957,6 +2960,7 @@ bool InitializedEntity::allowsNRVO(<wbr>) con<br>
   case EK_Parameter:<br>
   case EK_Parameter_CF_Audited:<br>
   case EK_Member:<br>
+  case EK_Binding:<br>
   case EK_New:<br>
   case EK_Temporary:<br>
   case EK_CompoundLiteralInit:<br>
@@ -2988,6 +2992,7 @@ unsigned InitializedEntity::dumpImpl(<wbr>raw<br>
   case EK_Result: OS << "Result"; break;<br>
   case EK_Exception: OS << "Exception"; break;<br>
   case EK_Member: OS << "Member"; break;<br>
+  case EK_Binding: OS << "Binding"; break;<br>
   case EK_New: OS << "New"; break;<br>
   case EK_Temporary: OS << "Temporary"; break;<br>
   case EK_CompoundLiteralInit: OS << "CompoundLiteral";break;<br>
@@ -3004,9 +3009,9 @@ unsigned InitializedEntity::dumpImpl(<wbr>raw<br>
     break;<br>
   }<br>
<br>
-  if (Decl *D = getDecl()) {<br>
+  if (auto *D = getDecl()) {<br>
     OS << " ";<br>
-    cast<NamedDecl>(D)-><wbr>printQualifiedName(OS);<br>
+    D->printQualifiedName(OS);<br>
   }<br>
<br>
   OS << " '" << getType().getAsString() << "'\n";<br>
@@ -5270,6 +5275,7 @@ getAssignmentAction(const InitializedEnt<br>
     return Sema::AA_Casting;<br>
<br>
   case InitializedEntity::EK_Member:<br>
+  case InitializedEntity::EK_Binding:<br>
   case InitializedEntity::EK_<wbr>ArrayElement:<br>
   case InitializedEntity::EK_<wbr>VectorElement:<br>
   case InitializedEntity::EK_<wbr>ComplexElement:<br>
@@ -5305,6 +5311,7 @@ static bool shouldBindAsTemporary(const<br>
   case InitializedEntity::EK_<wbr>Parameter_CF_Audited:<br>
   case InitializedEntity::EK_<wbr>Temporary:<br>
   case InitializedEntity::EK_<wbr>RelatedResult:<br>
+  case InitializedEntity::EK_Binding:<br>
     return true;<br>
   }<br>
<br>
@@ -5326,6 +5333,7 @@ static bool shouldDestroyTemporary(const<br>
       return false;<br>
<br>
     case InitializedEntity::EK_Member:<br>
+    case InitializedEntity::EK_Binding:<br>
     case InitializedEntity::EK_<wbr>Variable:<br>
     case InitializedEntity::EK_<wbr>Parameter:<br>
     case InitializedEntity::EK_<wbr>Parameter_CF_Audited:<br>
@@ -5395,6 +5403,7 @@ static SourceLocation getInitializationL<br>
     return Entity.getThrowLoc();<br>
<br>
   case InitializedEntity::EK_<wbr>Variable:<br>
+  case InitializedEntity::EK_Binding:<br>
     return Entity.getDecl()->getLocation(<wbr>);<br>
<br>
   case InitializedEntity::EK_<wbr>LambdaCapture:<br>
@@ -5826,6 +5835,7 @@ InitializedEntityOutlivesFullE<wbr>xpression(<br>
   case InitializedEntity::EK_Result:<br>
   case InitializedEntity::EK_<wbr>Exception:<br>
   case InitializedEntity::EK_Member:<br>
+  case InitializedEntity::EK_Binding:<br>
   case InitializedEntity::EK_New:<br>
   case InitializedEntity::EK_Base:<br>
   case InitializedEntity::EK_<wbr>Delegating:<br>
@@ -5875,6 +5885,9 @@ static const InitializedEntity *getEntit<br>
     //      ctor-initializer persists until the constructor exits.<br>
     return Entity;<br>
<br>
+  case InitializedEntity::EK_Binding:<br>
+    return getEntityForTemporaryLifetimeE<wbr>xtension(Entity->getParent(), nullptr);<br>
+<br>
   case InitializedEntity::EK_<wbr>Parameter:<br>
   case InitializedEntity::EK_<wbr>Parameter_CF_Audited:<br>
     //   -- A temporary bound to a reference parameter in a function call<br>
@@ -6250,7 +6263,7 @@ InitializationSequence::<wbr>Perform(Sema &S,<br>
           SourceRange Brackets;<br>
<br>
           // Scavange the location of the brackets from the entity, if we can.<br>
-          if (DeclaratorDecl *DD = Entity.getDecl()) {<br>
+          if (auto *DD = dyn_cast_or_null<<wbr>DeclaratorDecl>(Entity.<wbr>getDecl())) {<br>
             if (TypeSourceInfo *TInfo = DD->getTypeSourceInfo()) {<br>
               TypeLoc TL = TInfo->getTypeLoc();<br>
               if (IncompleteArrayTypeLoc ArrayLoc =<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaTemplate.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaTemplate.cpp?rev=278435&<wbr>r1=278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaTemplate.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaTemplate.cpp Thu Aug 11 17:25:46 2016<br>
@@ -2073,11 +2073,8 @@ checkBuiltinTemplateIdType(<wbr>Sema &SemaRef<br>
     for (llvm::APSInt I(NumArgs.getBitWidth(), NumArgs.isUnsigned());<br>
          I < NumArgs; ++I) {<br>
       TemplateArgument TA(Context, I, ArgTy);<br>
-      Expr *E = SemaRef.<wbr>BuildExpressionFromIntegralTem<wbr>plateArgument(<br>
-                           TA, TemplateArgs[2].getLocation())<br>
-                    .getAs<Expr>();<br>
-      SyntheticTemplateArgs.<wbr>addArgument(<br>
-          TemplateArgumentLoc(<wbr>TemplateArgument(E), E));<br>
+      SyntheticTemplateArgs.<wbr>addArgument(SemaRef.<wbr>getTrivialTemplateArgumentLoc(<br>
+          TA, ArgTy, TemplateArgs[2].getLocation())<wbr>);<br>
     }<br>
     // The first template argument will be reused as the template decl that<br>
     // our synthetic template arguments will be applied to.<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaTemplateDeduction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaTemplateDeduction.cpp?rev=<wbr>278435&r1=278434&r2=278435&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaTemplateDeduction.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaTemplateDeduction.cpp Thu Aug 11 17:25:46 2016<br>
@@ -2002,37 +2002,33 @@ static bool isSameTemplateArg(ASTContext<br>
 ///<br>
 /// \param Loc The source location to use for the resulting template<br>
 /// argument.<br>
-static TemplateArgumentLoc<br>
-<wbr>getTrivialTemplateArgumentLoc(<wbr>Sema &S,<br>
-                              const TemplateArgument &Arg,<br>
-                              QualType NTTPType,<br>
-                              SourceLocation Loc) {<br>
+TemplateArgumentLoc<br>
+Sema::<wbr>getTrivialTemplateArgumentLoc(<wbr>const TemplateArgument &Arg,<br>
+                                    QualType NTTPType, SourceLocation Loc) {<br>
   switch (Arg.getKind()) {<br>
   case TemplateArgument::Null:<br>
     llvm_unreachable("Can't get a NULL template argument here");<br>
<br>
   case TemplateArgument::Type:<br>
-    return TemplateArgumentLoc(Arg,<br>
-                     S.Context.<wbr>getTrivialTypeSourceInfo(Arg.<wbr>getAsType(), Loc));<br>
+    return TemplateArgumentLoc(<br>
+        Arg, Context.<wbr>getTrivialTypeSourceInfo(Arg.<wbr>getAsType(), Loc));<br>
<br>
   case TemplateArgument::Declaration: {<br>
-    Expr *E<br>
-      = S.<wbr>BuildExpressionFromDeclTemplat<wbr>eArgument(Arg, NTTPType, Loc)<br>
-          .getAs<Expr>();<br>
+    Expr *E = BuildExpressionFromDeclTemplat<wbr>eArgument(Arg, NTTPType, Loc)<br>
+                  .getAs<Expr>();<br>
     return TemplateArgumentLoc(<wbr>TemplateArgument(E), E);<br>
   }<br>
<br>
   case TemplateArgument::NullPtr: {<br>
-    Expr *E<br>
-      = S.<wbr>BuildExpressionFromDeclTemplat<wbr>eArgument(Arg, NTTPType, Loc)<br>
-          .getAs<Expr>();<br>
+    Expr *E = BuildExpressionFromDeclTemplat<wbr>eArgument(Arg, NTTPType, Loc)<br>
+                  .getAs<Expr>();<br>
     return TemplateArgumentLoc(<wbr>TemplateArgument(NTTPType, /*isNullPtr*/true),<br>
                                E);<br>
   }<br>
<br>
   case TemplateArgument::Integral: {<br>
-    Expr *E<br>
-      = S.<wbr>BuildExpressionFromIntegralTem<wbr>plateArgument(Arg, Loc).getAs<Expr>();<br>
+    Expr *E =<br>
+        BuildExpressionFromIntegralTem<wbr>plateArgument(Arg, Loc).getAs<Expr>();<br>
     return TemplateArgumentLoc(<wbr>TemplateArgument(E), E);<br>
   }<br>
<br>
@@ -2041,18 +2037,16 @@ getTrivialTemplateArgumentLoc(<wbr>Sema &S,<br>
       NestedNameSpecifierLocBuilder Builder;<br>
       TemplateName Template = Arg.getAsTemplate();<br>
       if (DependentTemplateName *DTN = Template.<wbr>getAsDependentTemplateName())<br>
-        Builder.MakeTrivial(S.Context, DTN->getQualifier(), Loc);<br>
+        Builder.MakeTrivial(Context, DTN->getQualifier(), Loc);<br>
       else if (QualifiedTemplateName *QTN =<br>
                    Template.<wbr>getAsQualifiedTemplateName())<br>
-        Builder.MakeTrivial(S.Context, QTN->getQualifier(), Loc);<br>
+        Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);<br>
<br>
       if (Arg.getKind() == TemplateArgument::Template)<br>
-        return TemplateArgumentLoc(Arg,<br>
-                                   Builder.getWithLocInContext(S.<wbr>Context),<br>
+        return TemplateArgumentLoc(Arg, Builder.getWithLocInContext(<wbr>Context),<br>
                                    Loc);<br>
-<br>
-<br>
-      return TemplateArgumentLoc(Arg, Builder.getWithLocInContext(S.<wbr>Context),<br>
+<br>
+      return TemplateArgumentLoc(Arg, Builder.getWithLocInContext(<wbr>Context),<br>
                                  Loc, Loc);<br>
     }<br>
<br>
@@ -2100,7 +2094,7 @@ ConvertDeducedTemplateArgument<wbr>(Sema &S,<br>
     // argument that we can check, almost as if the user had written<br>
     // the template argument explicitly.<br>
     TemplateArgumentLoc ArgLoc =<br>
-        getTrivialTemplateArgumentLoc(<wbr>S, Arg, NTTPType, Info.getLocation());<br>
+        S.<wbr>getTrivialTemplateArgumentLoc(<wbr>Arg, NTTPType, Info.getLocation());<br>
<br>
     // Check the template argument, converting it as necessary.<br>
     return S.CheckTemplateArgument(<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaType.cpp?rev=278435&r1=<wbr>278434&r2=278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaType.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.<wbr>cpp Thu Aug 11 17:25:46 2016<br>
@@ -1748,6 +1748,12 @@ QualType Sema::BuildQualifiedType(<wbr>QualTy<br>
   if (T.isNull())<br>
     return QualType();<br>
<br>
+  // Ignore any attempt to form a cv-qualified reference.<br>
+  if (T->isReferenceType()) {<br>
+    Qs.removeConst();<br>
+    Qs.removeVolatile();<br>
+  }<br>
+<br>
   // Enforce C99 6.7.3p2: "Types other than pointer types derived from<br>
   // object or incomplete types shall not be restrict-qualified."<br>
   if (Qs.hasRestrict()) {<br>
@@ -1789,6 +1795,11 @@ QualType Sema::BuildQualifiedType(<wbr>QualTy<br>
   if (T.isNull())<br>
     return QualType();<br>
<br>
+  // Ignore any attempt to form a cv-qualified reference.<br>
+  if (T->isReferenceType())<br>
+    CVRAU &=<br>
+        ~(DeclSpec::TQ_const | DeclSpec::TQ_volatile | DeclSpec::TQ_atomic);<br>
+<br>
   // Convert from DeclSpec::TQ to Qualifiers::TQ by just dropping TQ_atomic and<br>
   // TQ_unaligned;<br>
   unsigned CVR = CVRAU & ~(DeclSpec::TQ_atomic | DeclSpec::TQ_unaligned);<br>
<br>
Added: cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p2.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p2.cpp?rev=278435&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>dcl.decl/dcl.decomp/p2.cpp?<wbr>rev=278435&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p2.cpp (added)<br>
+++ cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p2.cpp Thu Aug 11 17:25:46 2016<br>
@@ -0,0 +1,22 @@<br>
+// RUN: %clang_cc1 -std=c++1z -verify %s<br>
+<br>
+int array() {<br>
+  int arr[3] = {};<br>
+  // FIXME: We are supposed to create an array object here and perform elementwise initialization.<br>
+  auto [a, b, c] = arr; // expected-error {{cannot decompose non-class, non-array}}<br>
+<br>
+  auto &[d, e] = arr; // expected-error {{type 'int [3]' decomposes into 3 elements, but only 2 names were provided}}<br>
+  auto &[f, g, h, i] = arr; // expected-error {{type 'int [3]' decomposes into 3 elements, but 4 names were provided}}<br>
+<br>
+  auto &[r0, r1, r2] = arr;<br>
+  const auto &[cr0, cr1, cr2] = arr;<br>
+<br>
+  //static_assert(&arr[0] == &r0);<br>
+  //static_assert(&arr[0] == &cr0);<br>
+  using T = int;<br>
+  using T = decltype(r0);<br>
+  using U = const int;<br>
+  using U = decltype(cr0);<br>
+<br>
+  return r1 + cr2;<br>
+}<br>
<br>
Added: cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p3.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp?rev=278435&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>dcl.decl/dcl.decomp/p3.cpp?<wbr>rev=278435&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p3.cpp (added)<br>
+++ cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p3.cpp Thu Aug 11 17:25:46 2016<br>
@@ -0,0 +1,203 @@<br>
+// RUN: %clang_cc1 -std=c++1z -verify %s<br>
+<br>
+using size_t = decltype(sizeof(0));<br>
+<br>
+struct A { int x, y; };<br>
+struct B { int x, y; };<br>
+<br>
+void no_tuple_size_1() { auto [x, y] = A(); } // ok, decompose elementwise<br>
+<br>
+namespace std { template<typename T> struct tuple_size; }<br>
+void no_tuple_size_2() { auto [x, y] = A(); } // ok, decompose elementwise<br>
+<br>
+struct Bad1 {};<br>
+template<> struct std::tuple_size<Bad1> {};<br>
+void no_tuple_size_3() { auto [x, y] = Bad1(); } // expected-error {{cannot decompose this type; 'std::tuple_size<Bad1>::value' is not a valid integral constant expression}}<br>
+<br>
+struct Bad2 {};<br>
+template<> struct std::tuple_size<Bad2> { const int value = 5; };<br>
+void no_tuple_size_4() { auto [x, y] = Bad2(); } // expected-error {{cannot decompose this type; 'std::tuple_size<Bad2>::value' is not a valid integral constant expression}}<br>
+<br>
+template<> struct std::tuple_size<A> { static const int value = 3; };<br>
+template<> struct std::tuple_size<B> { enum { value = 3 }; };<br>
+<br>
+void no_get_1() {<br>
+  {<br>
+    auto [a0, a1] = A(); // expected-error {{decomposes into 3 elements}}<br>
+    auto [b0, b1] = B(); // expected-error {{decomposes into 3 elements}}<br>
+  }<br>
+  auto [a0, a1, a2] = A(); // expected-error {{undeclared identifier 'get'}} expected-note {{in implicit initialization of binding declaration 'a0'}}<br>
+}<br>
+<br>
+int get(A);<br>
+<br>
+void no_get_2() {<br>
+  // FIXME: This diagnostic is not great.<br>
+  auto [a0, a1, a2] = A(); // expected-error {{undeclared identifier 'get'}} expected-note {{in implicit initialization of binding declaration 'a0'}}<br>
+}<br>
+<br>
+template<int> float &get(A);<br>
+<br>
+void no_tuple_element_1() {<br>
+  auto [a0, a1, a2] = A(); // expected-error-re {{'std::tuple_element<0U{{L*}}<wbr>, A>::type' does not name a type}} expected-note {{in implicit}}<br>
+}<br>
+<br>
+namespace std { template<size_t, typename> struct tuple_element; } // expected-note 2{{here}}<br>
+<br>
+void no_tuple_element_2() {<br>
+  auto [a0, a1, a2] = A(); // expected-error {{implicit instantiation of undefined template 'std::tuple_element<0, A>'}} expected-note {{in implicit}}<br>
+}<br>
+<br>
+template<> struct std::tuple_element<0, A> { typedef float type; };<br>
+<br>
+void no_tuple_element_3() {<br>
+  auto [a0, a1, a2] = A(); // expected-error {{implicit instantiation of undefined template 'std::tuple_element<1, A>'}} expected-note {{in implicit}}<br>
+}<br>
+<br>
+template<> struct std::tuple_element<1, A> { typedef float &type; };<br>
+template<> struct std::tuple_element<2, A> { typedef const float &type; };<br>
+<br>
+template<int N> auto get(B) -> int (&)[N + 1];<br>
+template<int N> struct std::tuple_element<N, B> { typedef int type[N +1 ]; };<br>
+<br>
+template<typename T> struct std::tuple_size<const T> : std::tuple_size<T> {};<br>
+template<size_t N, typename T> struct std::tuple_element<N, const T> {<br>
+  typedef const typename std::tuple_element<N, T>::type type;<br>
+};<br>
+<br>
+void referenced_type() {<br>
+  auto [a0, a1, a2] = A();<br>
+  auto [b0, b1, b2] = B();<br>
+<br>
+  A a;<br>
+  B b;<br>
+  auto &[ar0, ar1, ar2] = a;<br>
+  auto &[br0, br1, br2] = b;<br>
+<br>
+  auto &&[arr0, arr1, arr2] = A();<br>
+  auto &&[brr0, brr1, brr2] = B();<br>
+<br>
+  const auto &[acr0, acr1, acr2] = A();<br>
+  const auto &[bcr0, bcr1, bcr2] = B();<br>
+<br>
+<br>
+  using Float = float;<br>
+  using Float = decltype(a0);<br>
+  using Float = decltype(ar0);<br>
+  using Float = decltype(arr0);<br>
+<br>
+  using ConstFloat = const float;<br>
+  using ConstFloat = decltype(acr0);<br>
+<br>
+  using FloatRef = float&;<br>
+  using FloatRef = decltype(a1);<br>
+  using FloatRef = decltype(ar1);<br>
+  using FloatRef = decltype(arr1);<br>
+  using FloatRef = decltype(acr1);<br>
+<br>
+  using ConstFloatRef = const float&;<br>
+  using ConstFloatRef = decltype(a2);<br>
+  using ConstFloatRef = decltype(ar2);<br>
+  using ConstFloatRef = decltype(arr2);<br>
+  using ConstFloatRef = decltype(acr2);<br>
+<br>
+<br>
+  using Int1 = int[1];<br>
+  using Int1 = decltype(b0);<br>
+  using Int1 = decltype(br0);<br>
+  using Int1 = decltype(brr0);<br>
+<br>
+  using ConstInt1 = const int[1];<br>
+  using ConstInt1 = decltype(bcr0);<br>
+<br>
+  using Int2 = int[2];<br>
+  using Int2 = decltype(b1);<br>
+  using Int2 = decltype(br1);<br>
+  using Int2 = decltype(brr1);<br>
+<br>
+  using ConstInt2 = const int[2];<br>
+  using ConstInt2 = decltype(bcr1);<br>
+<br>
+  using Int3 = int[3];<br>
+  using Int3 = decltype(b2);<br>
+  using Int3 = decltype(br2);<br>
+  using Int3 = decltype(brr2);<br>
+<br>
+  using ConstInt3 = const int[3];<br>
+  using ConstInt3 = decltype(bcr2);<br>
+}<br>
+<br>
+struct C { template<int> int get(); };<br>
+template<> struct std::tuple_size<C> { static const int value = 1; };<br>
+template<> struct std::tuple_element<0, C> { typedef int type; };<br>
+<br>
+int member_get() {<br>
+  auto [c] = C();<br>
+  using T = int;<br>
+  using T = decltype(c);<br>
+  return c;<br>
+}<br>
+<br>
+struct D { template<int> struct get {}; }; // expected-note {{declared here}}<br>
+template<> struct std::tuple_size<D> { static const int value = 1; };<br>
+template<> struct std::tuple_element<0, D> { typedef D::get<0> type; };<br>
+void member_get_class_template() {<br>
+  auto [d] = D(); // expected-error {{cannot refer to member 'get' in 'D' with '.'}} expected-note {{in implicit init}}<br>
+}<br>
+<br>
+struct E { int get(); };<br>
+template<> struct std::tuple_size<E> { static const int value = 1; };<br>
+template<> struct std::tuple_element<0, E> { typedef int type; };<br>
+void member_get_non_template() {<br>
+  // FIXME: This diagnostic is not very good.<br>
+  auto [e] = E(); // expected-error {{no member named 'get'}} expected-note {{in implicit init}}<br>
+}<br>
+<br>
+namespace ADL {<br>
+  struct X {};<br>
+};<br>
+template<int> int get(ADL::X);<br>
+template<> struct std::tuple_size<ADL::X> { static const int value = 1; };<br>
+template<> struct std::tuple_element<0, ADL::X> { typedef int type; };<br>
+void adl_only_bad() {<br>
+  auto [x] = ADL::X(); // expected-error {{undeclared identifier 'get'}} expected-note {{in implicit init}}<br>
+}<br>
+<br>
+template<typename ElemType, typename GetTypeLV, typename GetTypeRV><br>
+struct wrap {<br>
+  template<size_t> GetTypeLV get() &;<br>
+  template<size_t> GetTypeRV get() &&;<br>
+};<br>
+template<typename ET, typename GTL, typename GTR><br>
+struct std::tuple_size<wrap<ET, GTL, GTR>> {<br>
+  static const int value = 1;<br>
+};<br>
+template<typename ET, typename GTL, typename GTR><br>
+struct std::tuple_element<0, wrap<ET, GTL, GTR>> {<br>
+  using type = ET;<br>
+};<br>
+<br>
+template<typename T> T &lvalue();<br>
+<br>
+void test_value_category() {<br>
+  // If the declared variable is an lvalue reference, the operand to get is an<br>
+  // lvalue. Otherwise it's an xvalue.<br>
+  { auto [a] = wrap<int, void, int>(); }<br>
+  { auto &[a] = lvalue<wrap<int, int, void>>(); }<br>
+  { auto &&[a] = wrap<int, void, int>(); }<br>
+  // If the initializer (call to get) is an lvalue, the binding is an lvalue<br>
+  // reference to the element type. Otherwise it's an rvalue reference to the<br>
+  // element type.<br>
+  { auto [a] = wrap<int, void, int&>(); }<br>
+  { auto [a] = wrap<int&, void, int&>(); }<br>
+  { auto [a] = wrap<int&&, void, int&>(); } // ok, reference collapse to int&<br>
+<br>
+  { auto [a] = wrap<int, void, int&&>(); }<br>
+  { auto [a] = wrap<int&, void, int&&>(); } // expected-error {{non-const lvalue reference to type 'int' cannot bind}} expected-note {{in implicit}}<br>
+  { auto [a] = wrap<const int&, void, int&&>(); }<br>
+  { auto [a] = wrap<int&&, void, int&&>(); }<br>
+<br>
+  { auto [a] = wrap<int, void, float&>(); } // expected-error {{cannot bind}} expected-note {{implicit}}<br>
+  { auto [a] = wrap<const int, void, float&>(); } // ok, const int &a can bind to float<br>
+  { auto [a] = wrap<int, void, float>(); } // ok, int &&a can bind to float<br>
+}<br>
<br>
Added: cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p4.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p4.cpp?rev=278435&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>dcl.decl/dcl.decomp/p4.cpp?<wbr>rev=278435&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p4.cpp (added)<br>
+++ cfe/trunk/test/CXX/dcl.decl/<wbr>dcl.decomp/p4.cpp Thu Aug 11 17:25:46 2016<br>
@@ -0,0 +1,173 @@<br>
+// RUN: %clang_cc1 -std=c++1z -verify -triple i686-linux-gnu %s<br>
+<br>
+template<typename T, typename U> struct same;<br>
+template<typename T> struct same<T, T> { ~same(); };<br>
+<br>
+struct Empty {};<br>
+<br>
+struct A {<br>
+  int a;<br>
+};<br>
+<br>
+namespace NonPublicMembers {<br>
+  struct NonPublic1 {<br>
+  protected:<br>
+    int a; // expected-note {{declared protected here}}<br>
+  };<br>
+<br>
+  struct NonPublic2 {<br>
+  private:<br>
+    int a; // expected-note 2{{declared private here}}<br>
+  };<br>
+<br>
+  struct NonPublic3 : private A {}; // expected-note {{constrained by private inheritance}}<br>
+<br>
+  struct NonPublic4 : NonPublic2 {};<br>
+<br>
+  void test() {<br>
+    auto [a1] = NonPublic1(); // expected-error {{cannot decompose non-public member 'a' of 'NonPublicMembers::NonPublic1'<wbr>}}<br>
+    auto [a2] = NonPublic2(); // expected-error {{cannot decompose non-public member 'a' of 'NonPublicMembers::NonPublic2'<wbr>}}<br>
+    auto [a3] = NonPublic3(); // expected-error {{cannot decompose members of non-public base class 'A' of 'NonPublic3'}}<br>
+    auto [a4] = NonPublic4(); // expected-error {{cannot decompose non-public member 'a' of 'NonPublicMembers::NonPublic4'<wbr>}}<br>
+  }<br>
+}<br>
+<br>
+namespace MultipleClasses {<br>
+  struct B : A {<br>
+    int a;<br>
+  };<br>
+<br>
+  struct C { int a; };<br>
+  struct D : A, C {};<br>
+<br>
+  struct E : virtual A {};<br>
+  struct F : A, E {}; // expected-warning {{direct base 'A' is inaccessible due to ambiguity}}<br>
+<br>
+  struct G : virtual A {};<br>
+  struct H : E, G {};<br>
+<br>
+  struct I { int i; };<br>
+  struct J : I {};<br>
+  struct K : I, virtual J {}; // expected-warning {{direct base 'MultipleClasses::I' is inaccessible due to ambiguity}}<br>
+<br>
+  struct L : virtual J {};<br>
+  struct M : virtual J, L {};<br>
+<br>
+  void test() {<br>
+    auto [b] = B(); // expected-error {{cannot decompose class type 'B': both it and its base class 'A' have non-static data members}}<br>
+    auto [d] = D(); // expected-error {{cannot decompose class type 'D': its base classes 'A' and 'MultipleClasses::C' have non-static data members}}<br>
+    auto [e] = E();<br>
+    auto [f] = F(); // expected-error-re {{cannot decompose members of ambiguous base class 'A' of 'F':{{.*}}struct MultipleClasses::F -> struct A{{.*}}struct MultipleClasses::F -> struct MultipleClasses::E -> struct A}}<br>
+    auto [h] = H(); // ok, only one (virtual) base subobject even though there are two paths to it<br>
+    auto [k] = K(); // expected-error {{cannot decompose members of ambiguous base class 'MultipleClasses::I'}}<br>
+    auto [m] = M(); // ok, all paths to I are through the same virtual base subobject J<br>
+<br>
+    same<decltype(m), int>();<br>
+  }<br>
+}<br>
+<br>
+namespace BindingTypes {<br>
+  struct A {<br>
+    int i = 0;<br>
+    int &r = i;<br>
+    const float f = i;<br>
+    mutable volatile int mvi;<br>
+  };<br>
+  void e() {<br>
+    auto [i,r,f,mvi] = A();<br>
+<br>
+    same<decltype(i), int>();<br>
+    same<decltype(r), int&>();<br>
+    same<decltype(f), const float>();<br>
+    same<decltype(mvi), volatile int>();<br>
+<br>
+    same<decltype((i)), int&>();<br>
+    same<decltype((r)), int&>();<br>
+    same<decltype((f)), const float&>();<br>
+    same<decltype((mvi)), volatile int&>();<br>
+  }<br>
+  void f() {<br>
+    auto &&[i,r,f,mvi] = A();<br>
+<br>
+    same<decltype(i), int>();<br>
+    same<decltype(r), int&>();<br>
+    same<decltype(f), const float>();<br>
+    same<decltype(mvi), volatile int>();<br>
+<br>
+    same<decltype((i)), int&>();<br>
+    same<decltype((r)), int&>();<br>
+    same<decltype((f)), const float&>();<br>
+    same<decltype((mvi)), volatile int&>();<br>
+  }<br>
+  void g() {<br>
+    const auto [i,r,f,mvi] = A();<br>
+<br>
+    same<decltype(i), const int>();<br>
+    same<decltype(r), int&>();<br>
+    same<decltype(f), const float>();<br>
+    same<decltype(mvi), volatile int>(); // not 'const volatile int', per expected resolution of DRxxx<br>
+<br>
+    same<decltype((i)), const int&>();<br>
+    same<decltype((r)), int&>();<br>
+    same<decltype((f)), const float&>();<br>
+    same<decltype((mvi)), volatile int&>(); // not 'const volatile int&', per expected resolution of DRxxx<br>
+  }<br>
+  void h() {<br>
+    typedef const A CA;<br>
+    auto &[i,r,f,mvi] = CA(); // type of var is 'const A &'<br>
+<br>
+    same<decltype(i), const int>(); // not 'int', per expected resolution of DRxxx<br>
+    same<decltype(r), int&>();<br>
+    same<decltype(f), const float>();<br>
+    same<decltype(mvi), volatile int>(); // not 'const volatile int', per expected resolution of DRxxx<br>
+<br>
+    same<decltype((i)), const int&>(); // not 'int&', per expected resolution of DRxxx<br>
+    same<decltype((r)), int&>();<br>
+    same<decltype((f)), const float&>();<br>
+    same<decltype((mvi)), volatile int&>(); // not 'const volatile int&', per expected resolution of DRxxx<br>
+  }<br>
+  struct B {<br>
+    mutable int i;<br>
+  };<br>
+  void mut() {<br>
+    auto [i] = B();<br>
+    const auto [ci] = B();<br>
+    volatile auto [vi] = B();<br>
+    same<decltype(i), int>();<br>
+    same<decltype(ci), int>();<br>
+    same<decltype(vi), volatile int>();<br>
+  }<br>
+}<br>
+<br>
+namespace Bitfield {<br>
+  struct S { unsigned long long x : 4, y : 32; int z; }; // expected-note 2{{here}}<br>
+  int f(S s) {<br>
+    auto [a, b, c] = s;<br>
+    unsigned long long &ra = a; // expected-error {{bit-field 'x'}}<br>
+    unsigned long long &rb = b; // expected-error {{bit-field 'y'}}<br>
+    int &rc = c;<br>
+<br>
+    // the type of the binding is the type of the field<br>
+    same<decltype(a), unsigned long long>();<br>
+    same<decltype(b), unsigned long long>();<br>
+<br>
+    // the type of the expression is an lvalue of the field type<br>
+    // (even though a reference can't bind to the field)<br>
+    same<decltype((a)), unsigned long long&>();<br>
+    same<decltype((b)), unsigned long long&>();<br>
+<br>
+    // the expression promotes to a type large enough to hold the result<br>
+    same<decltype(+a), int>();<br>
+    same<decltype(+b), unsigned int>();<br>
+    return rc;<br>
+  }<br>
+}<br>
+<br>
+namespace std_example {<br>
+  struct S { int x1 : 2; volatile double y1; };<br>
+  S f();<br>
+  const auto [x, y] = f();<br>
+<br>
+  same<decltype((x)), const int&> same1;<br>
+  same<decltype((y)), const volatile double&> same2;<br>
+}<br>
<br>
Modified: cfe/trunk/test/Parser/cxx1z-<wbr>decomposition.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-decomposition.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/Parser/<wbr>cxx1z-decomposition.cpp?rev=<wbr>278435&r1=278434&r2=278435&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Parser/cxx1z-<wbr>decomposition.cpp (original)<br>
+++ cfe/trunk/test/Parser/cxx1z-<wbr>decomposition.cpp Thu Aug 11 17:25:46 2016<br>
@@ -67,7 +67,7 @@ namespace BadSpecifiers {<br>
     // storage-class-specifiers<br>
     static auto &[a] = n; // expected-error {{cannot be declared 'static'}}<br>
     thread_local auto &[b] = n; // expected-error {{cannot be declared 'thread_local'}}<br>
-    extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}}<br>
+    extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{cannot have an initializer}}<br>
     struct S {<br>
       mutable auto &[d] = n; // expected-error {{not permitted in this context}}<br>
<br>
@@ -97,7 +97,7 @@ namespace BadSpecifiers {<br>
     auto [e][1] = s; // expected-error {{expected ';'}} expected-error {{requires an initializer}}<br>
<br>
     // FIXME: This should fire the 'misplaced array declarator' diagnostic.<br>
-    int [K] arr = {0}; // expected-error {{expected ';'}} expected-error {{cannot be declared with type 'int'}}<br>
+    int [K] arr = {0}; // expected-error {{expected ';'}} expected-error {{cannot be declared with type 'int'}} expected-error {{decomposition declaration '[K]' requires an initializer}}<br>
     int [5] arr = {0}; // expected-error {{place the brackets after the name}}<br>
<br>
     auto *[f] = s; // expected-error {{cannot be declared with type 'auto *'}} expected-error {{incompatible initializer}}<br>
@@ -133,3 +133,16 @@ namespace Template {<br>
   // FIXME: There's no actual rule against this...<br>
   template<typename T> auto [a, b, c] = n; // expected-error {{decomposition declaration template not supported}}<br>
 }<br>
+<br>
+namespace Init {<br>
+  void f() {<br>
+    int arr[1];<br>
+    struct S { int n; };<br>
+    auto &[bad1]; // expected-error {{decomposition declaration '[bad1]' requires an initializer}}<br>
+    const auto &[bad2](S{}); // expected-error {{decomposition declaration '[bad2]' cannot have a parenthesized initializer}}<br>
+    auto &[good1] = arr;<br>
+    auto &&[good2] = S{};<br>
+    S [goodish3] = { 4 }; // expected-error {{cannot be declared with type 'S'}}<br>
+    S [goodish4] { 4 }; // expected-error {{cannot be declared with type 'S'}}<br>
+  }<br>
+}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/cxx1z-<wbr>decomposition.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp?rev=278435&r1=278434&r2=278435&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/cxx1z-decomposition.<wbr>cpp?rev=278435&r1=278434&r2=<wbr>278435&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/cxx1z-<wbr>decomposition.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/cxx1z-<wbr>decomposition.cpp Thu Aug 11 17:25:46 2016<br>
@@ -4,7 +4,23 @@ void use_from_own_init() {<br>
   auto [a] = a; // expected-error {{binding 'a' cannot appear in the initializer of its own decomposition declaration}}<br>
 }<br>
<br>
-// FIXME: create correct bindings<br>
+// As a Clang extension, _Complex can be decomposed.<br>
+float decompose_complex(_Complex float cf) {<br>
+  auto [re, im] = cf;<br>
+  //static_assert(&re == &__real cf);<br>
+  //static_assert(&im == &__imag cf);<br>
+  return re*re + im*im;<br>
+}<br>
+<br>
+// As a Clang extension, vector types can be decomposed.<br>
+typedef float vf3 __attribute__((ext_vector_<wbr>type(3)));<br>
+float decompose_vector(vf3 v) {<br>
+  auto [x, y, z] = v;<br>
+  auto *p = &x; // expected-error {{address of vector element requested}}<br>
+  return x + y + z;<br>
+}<br>
+<br>
+// FIXME: by-value array copies<br>
 // FIXME: template instantiation<br>
 // FIXME: ast file support<br>
 // FIXME: code generation<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>