From owner-svn-src-vendor@freebsd.org Sat Dec 16 14:45:39 2017 Return-Path: Delivered-To: svn-src-vendor@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 12406E84817; Sat, 16 Dec 2017 14:45:39 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DE5E266900; Sat, 16 Dec 2017 14:45:38 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBGEjbp0032460; Sat, 16 Dec 2017 14:45:37 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBGEjbhg032455; Sat, 16 Dec 2017 14:45:37 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201712161445.vBGEjbhg032455@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Sat, 16 Dec 2017 14:45:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r326901 - in vendor/clang/dist: lib/Basic lib/Sema test/SemaCXX X-SVN-Group: vendor X-SVN-Commit-Author: dim X-SVN-Commit-Paths: in vendor/clang/dist: lib/Basic lib/Sema test/SemaCXX X-SVN-Commit-Revision: 326901 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-vendor@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the vendor work area tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Dec 2017 14:45:39 -0000 Author: dim Date: Sat Dec 16 14:45:37 2017 New Revision: 326901 URL: https://svnweb.freebsd.org/changeset/base/326901 Log: Vendor import of clang 5.0.1 release r320880: https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_501/final@320880 Modified: vendor/clang/dist/lib/Basic/Version.cpp vendor/clang/dist/lib/Sema/SemaDecl.cpp vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp vendor/clang/dist/lib/Sema/SemaTemplateInstantiateDecl.cpp vendor/clang/dist/test/SemaCXX/unused.cpp Modified: vendor/clang/dist/lib/Basic/Version.cpp ============================================================================== --- vendor/clang/dist/lib/Basic/Version.cpp Sat Dec 16 14:44:39 2017 (r326900) +++ vendor/clang/dist/lib/Basic/Version.cpp Sat Dec 16 14:45:37 2017 (r326901) @@ -36,7 +36,7 @@ std::string getClangRepositoryPath() { // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us // pick up a tag in an SVN export, for example. - StringRef SVNRepository("$URL: https://llvm.org/svn/llvm-project/cfe/branches/release_50/lib/Basic/Version.cpp $"); + StringRef SVNRepository("$URL: https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_501/final/lib/Basic/Version.cpp $"); if (URL.empty()) { URL = SVNRepository.slice(SVNRepository.find(':'), SVNRepository.find("/lib/Basic")); Modified: vendor/clang/dist/lib/Sema/SemaDecl.cpp ============================================================================== --- vendor/clang/dist/lib/Sema/SemaDecl.cpp Sat Dec 16 14:44:39 2017 (r326900) +++ vendor/clang/dist/lib/Sema/SemaDecl.cpp Sat Dec 16 14:45:37 2017 (r326901) @@ -1603,7 +1603,24 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl * if (D->isInvalidDecl()) return false; - if (D->isReferenced() || D->isUsed() || D->hasAttr() || + bool Referenced = false; + if (auto *DD = dyn_cast(D)) { + // For a decomposition declaration, warn if none of the bindings are + // referenced, instead of if the variable itself is referenced (which + // it is, by the bindings' expressions). + for (auto *BD : DD->bindings()) { + if (BD->isReferenced()) { + Referenced = true; + break; + } + } + } else if (!D->getDeclName()) { + return false; + } else if (D->isReferenced() || D->isUsed()) { + Referenced = true; + } + + if (Referenced || D->hasAttr() || D->hasAttr()) return false; @@ -1726,7 +1743,7 @@ void Sema::DiagnoseUnusedDecl(const NamedDecl *D) { else DiagID = diag::warn_unused_variable; - Diag(D->getLocation(), DiagID) << D->getDeclName() << Hint; + Diag(D->getLocation(), DiagID) << D << Hint; } static void CheckPoppedLabel(LabelDecl *L, Sema &S) { @@ -1756,8 +1773,6 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) assert(isa(TmpD) && "Decl isn't NamedDecl?"); NamedDecl *D = cast(TmpD); - if (!D->getDeclName()) continue; - // Diagnose unused variables in this scope. if (!S->hasUnrecoverableErrorOccurred()) { DiagnoseUnusedDecl(D); @@ -1765,6 +1780,8 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) DiagnoseUnusedNestedTypedefs(RD); } + if (!D->getDeclName()) continue; + // If this was a forward reference to a label, verify it was defined. if (LabelDecl *LD = dyn_cast(D)) CheckPoppedLabel(LD, *this); @@ -6155,7 +6172,6 @@ NamedDecl *Sema::ActOnVariableDeclarator( IdentifierInfo *II = Name.getAsIdentifierInfo(); if (D.isDecompositionDeclarator()) { - AddToScope = false; // Take the name of the first declarator as our name for diagnostic // purposes. auto &Decomp = D.getDecompositionDeclarator(); Modified: vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp ============================================================================== --- vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp Sat Dec 16 14:44:39 2017 (r326900) +++ vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp Sat Dec 16 14:45:37 2017 (r326901) @@ -826,7 +826,10 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarato NamedDecl *New = ActOnVariableDeclarator(S, D, DC, TInfo, Previous, MultiTemplateParamsArg(), AddToScope, Bindings); - CurContext->addHiddenDecl(New); + if (AddToScope) { + S->AddDecl(New); + CurContext->addHiddenDecl(New); + } if (isInOpenMPDeclareTargetContext()) checkDeclIsAllowedInOpenMPTarget(nullptr, New); Modified: vendor/clang/dist/lib/Sema/SemaTemplateInstantiateDecl.cpp ============================================================================== --- vendor/clang/dist/lib/Sema/SemaTemplateInstantiateDecl.cpp Sat Dec 16 14:44:39 2017 (r326900) +++ vendor/clang/dist/lib/Sema/SemaTemplateInstantiateDecl.cpp Sat Dec 16 14:45:37 2017 (r326901) @@ -677,6 +677,7 @@ TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(T Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) { auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier()); + NewBD->setReferenced(D->isReferenced()); SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD); return NewBD; } Modified: vendor/clang/dist/test/SemaCXX/unused.cpp ============================================================================== --- vendor/clang/dist/test/SemaCXX/unused.cpp Sat Dec 16 14:44:39 2017 (r326900) +++ vendor/clang/dist/test/SemaCXX/unused.cpp Sat Dec 16 14:45:37 2017 (r326901) @@ -1,6 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wunused %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wunused %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wunused %s // PR4103 : Make sure we don't get a bogus unused expression warning namespace PR4103 { @@ -8,7 +9,7 @@ namespace PR4103 { char foo; }; class APSInt : public APInt { - char bar; + char bar; // expected-warning {{private field 'bar' is not used}} public: APSInt &operator=(const APSInt &RHS); }; @@ -69,3 +70,44 @@ namespace UnresolvedLookup { } }; } + +#if __cplusplus >= 201703L +namespace PR33839 { + void a() { + struct X { int a, b; } x; + auto [a, b] = x; // expected-warning {{unused variable '[a, b]'}} + auto [c, d] = x; + (void)d; + } + + template void f() { + struct A { int n; } a[1]; + for (auto [x] : a) { + (void)x; + } + auto [y] = a[0]; // expected-warning {{unused}} + } + template void g() { + struct A { int n; } a[1]; + for (auto [x] : a) { + if constexpr (b) + (void)x; + } + + auto [y] = a[0]; + if constexpr (b) + (void)y; // ok, even when b == false + } + template void h() { + struct A { int n; } a[1]; + for (auto [x] : a) { // expected-warning {{unused variable '[x]'}} + } + } + void use() { + f(); // expected-note {{instantiation of}} + g(); + g(); + h(); // expected-note {{instantiation of}} + } +} +#endif