From: Richard Trieu Date: Fri, 11 Nov 2016 20:51:04 +0000 (+0000) Subject: When a DecompositionDecl is marked invalid, also set the child BindingDecl's to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=818a4ef94c024be07baca347d004b877ea6d9d06;p=clang When a DecompositionDecl is marked invalid, also set the child BindingDecl's to invalid. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286630 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 5d130acfbe..8deef3343d 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -109,12 +109,24 @@ const char *Decl::getDeclKindName() const { void Decl::setInvalidDecl(bool Invalid) { InvalidDecl = Invalid; assert(!isa(this) || !cast(this)->isCompleteDefinition()); - if (Invalid && !isa(this)) { + if (!Invalid) { + return; + } + + if (!isa(this)) { // Defensive maneuver for ill-formed code: we're likely not to make it to // a point where we set the access specifier, so default it to "public" // to avoid triggering asserts elsewhere in the front end. setAccess(AS_public); } + + // Marking a DecompositionDecl as invalid implies all the child BindingDecl's + // are invalid too. + if (DecompositionDecl *DD = dyn_cast(this)) { + for (BindingDecl *Binding : DD->bindings()) { + Binding->setInvalidDecl(); + } + } } const char *DeclContext::getDeclKindName() const { diff --git a/test/SemaCXX/cxx1z-decomposition.cpp b/test/SemaCXX/cxx1z-decomposition.cpp index 762dd7b94d..735a9e1dfe 100644 --- a/test/SemaCXX/cxx1z-decomposition.cpp +++ b/test/SemaCXX/cxx1z-decomposition.cpp @@ -53,4 +53,16 @@ void bitfield() { auto &[p, q, r] = a; // expected-error {{decomposes into 2 elements, but 3 names were provided}} } +void for_range() { + int x = 1; + for (auto[a, b] : x) { // expected-error {{invalid range expression of type 'int'; no viable 'begin' function available}} + a++; + } + + int y[5]; + for (auto[c] : y) { // expected-error {{cannot decompose non-class, non-array type 'int'}} + c++; + } +} + // FIXME: by-value array copies