From owner-svn-src-all@freebsd.org Tue Mar 7 21:44:06 2017 Return-Path: Delivered-To: svn-src-all@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 B24A3D019EF; Tue, 7 Mar 2017 21:44:06 +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 73009183E; Tue, 7 Mar 2017 21:44:06 +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 v27Li5WB074371; Tue, 7 Mar 2017 21:44:05 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v27Li52M074368; Tue, 7 Mar 2017 21:44:05 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201703072144.v27Li52M074368@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Tue, 7 Mar 2017 21:44:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r314883 - in stable/11/contrib/llvm/tools/clang: include/clang/Basic include/clang/Sema lib/Sema X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Mar 2017 21:44:06 -0000 Author: dim Date: Tue Mar 7 21:44:05 2017 New Revision: 314883 URL: https://svnweb.freebsd.org/changeset/base/314883 Log: Pull in r291403 from upstream clang trunk (by Richard Smith): PR30305: Implement proposed DR resolution to prevent slicing via inherited constructor. The rule we use is that a construction of a class type T from an argument of type U cannot use an inherited constructor if U is the same as T or is derived from T (or if the initialization would first convert it to such a type). This (approximately) matches the rule in use by GCC, and matches the current proposed DR resolution. Pull in r291955 from upstream clang trunk (by Richard Smith): PR31606: Generalize our tentative DR resolution for inheriting copy/move constructors to better match the pre-P0136R1 behavior. Together, these fix an issue with C++ using declarations sometimes enabling illegal implicit casts. Direct commit to stable/11, since head already has clang 4.0.0, which includes this change. Reported by: kami PR: 215969 Modified: stable/11/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td stable/11/contrib/llvm/tools/clang/include/clang/Sema/Overload.h stable/11/contrib/llvm/tools/clang/lib/Sema/SemaOverload.cpp Modified: stable/11/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td ============================================================================== --- stable/11/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 7 21:40:01 2017 (r314882) +++ stable/11/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 7 21:44:05 2017 (r314883) @@ -3180,6 +3180,9 @@ def note_ovl_candidate : Note<"candidate def note_ovl_candidate_inherited_constructor : Note< "constructor from base class %0 inherited here">; +def note_ovl_candidate_inherited_constructor_slice : Note< + "candidate %select{constructor|template}0 ignored: " + "inherited constructor cannot be used to %select{copy|move}1 object">; def note_ovl_candidate_illegal_constructor : Note< "candidate %select{constructor|template}0 ignored: " "instantiation %select{takes|would take}0 its own class type by value">; Modified: stable/11/contrib/llvm/tools/clang/include/clang/Sema/Overload.h ============================================================================== --- stable/11/contrib/llvm/tools/clang/include/clang/Sema/Overload.h Tue Mar 7 21:40:01 2017 (r314882) +++ stable/11/contrib/llvm/tools/clang/include/clang/Sema/Overload.h Tue Mar 7 21:44:05 2017 (r314883) @@ -586,7 +586,11 @@ namespace clang { ovl_fail_enable_if, /// This candidate was not viable because its address could not be taken. - ovl_fail_addr_not_available + ovl_fail_addr_not_available, + + /// This inherited constructor is not viable because it would slice the + /// argument. + ovl_fail_inhctor_slice, }; /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). Modified: stable/11/contrib/llvm/tools/clang/lib/Sema/SemaOverload.cpp ============================================================================== --- stable/11/contrib/llvm/tools/clang/lib/Sema/SemaOverload.cpp Tue Mar 7 21:40:01 2017 (r314882) +++ stable/11/contrib/llvm/tools/clang/lib/Sema/SemaOverload.cpp Tue Mar 7 21:44:05 2017 (r314883) @@ -5783,6 +5783,28 @@ Sema::AddOverloadCandidate(FunctionDecl Candidate.FailureKind = ovl_fail_illegal_constructor; return; } + + // C++ [over.match.funcs]p8: (proposed DR resolution) + // A constructor inherited from class type C that has a first parameter + // of type "reference to P" (including such a constructor instantiated + // from a template) is excluded from the set of candidate functions when + // constructing an object of type cv D if the argument list has exactly + // one argument and D is reference-related to P and P is reference-related + // to C. + auto *Shadow = dyn_cast(FoundDecl.getDecl()); + if (Shadow && Args.size() == 1 && Constructor->getNumParams() >= 1 && + Constructor->getParamDecl(0)->getType()->isReferenceType()) { + QualType P = Constructor->getParamDecl(0)->getType()->getPointeeType(); + QualType C = Context.getRecordType(Constructor->getParent()); + QualType D = Context.getRecordType(Shadow->getParent()); + SourceLocation Loc = Args.front()->getExprLoc(); + if ((Context.hasSameUnqualifiedType(P, C) || IsDerivedFrom(Loc, P, C)) && + (Context.hasSameUnqualifiedType(D, P) || IsDerivedFrom(Loc, D, P))) { + Candidate.Viable = false; + Candidate.FailureKind = ovl_fail_inhctor_slice; + return; + } + } } unsigned NumParams = Proto->getNumParams(); @@ -9750,6 +9772,17 @@ static void NoteFunctionCandidate(Sema & case ovl_fail_enable_if: return DiagnoseFailedEnableIfAttr(S, Cand); + case ovl_fail_inhctor_slice: + // It's generally not interesting to note copy/move constructors here. + if (cast(Fn)->isCopyOrMoveConstructor()) + return; + S.Diag(Fn->getLocation(), + diag::note_ovl_candidate_inherited_constructor_slice) + << (Fn->getPrimaryTemplate() ? 1 : 0) + << Fn->getParamDecl(0)->getType()->isRValueReferenceType(); + MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); + return; + case ovl_fail_addr_not_available: { bool Available = checkAddressOfCandidateIsAvailable(S, Cand->Function); (void)Available;