From patchwork Mon Jul 17 16:01:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 789587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xB7MB1mLnz9s06 for ; Tue, 18 Jul 2017 02:01:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LpLhukG6"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Gy8L5KsN7x9nurFq/QCKbejqQYTSXWjCIply0NVBscQIR3q7cR 95yR3T0LkZyX7brSZocdHZdLWMWjJoskDUIQTtknnu8rj4zfFHKpVTQIerNlj4bg ykpOqNoWFYynIb+22fltcWGAR9CaOZ4lKDuq87hxFwAyx3s+LIsNUHsUg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=gLelTaI6weVdpOx/a3wGZJxhZrY=; b=LpLhukG6nL7TRnKlhnYN pourOwWVSz6W8ewu2KBxha7DUEkYBh29N3zU+qc0npGnmnz4V7GGZjqdH+5cy2kW spOxpy5TPS2o9zN0sqAsbhkkvQTDkDglwdPcKCWUdwKxypLAM108lsEt5DTu5Tbr ZJzec06Lj4uW+dk88BinHI0= Received: (qmail 34574 invoked by alias); 17 Jul 2017 16:01:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 34546 invoked by uid 89); 17 Jul 2017 16:01:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:200, informed X-HELO: mail-yb0-f182.google.com Received: from mail-yb0-f182.google.com (HELO mail-yb0-f182.google.com) (209.85.213.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Jul 2017 16:01:13 +0000 Received: by mail-yb0-f182.google.com with SMTP id z37so2098078ybh.1 for ; Mon, 17 Jul 2017 09:01:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=KqOIo9lhi0e/aS5Ven3dgnSXqCUnw7UqlTSs9fYOXr0=; b=lJuqRDU05InOg3sonixm0qeBtaZclXGz523vuGGklu6cCdwCzw/cZHMnQ3F+TR/Fdb FK6Y6Qcos7+/rbgZHnPoKoJVSlPAOx8ROI/ppKOdhWXyMQnqLR+zaOpOZLfbllauaSwt lm7k8O8JQIa5Jxhk+g5oVieWvxU1245gS16F2FzzBIOP9O6ShSjFfxdkl7pmYQg0cSa1 gvyDnyhZf0HSij0cZAIYXZ3xVWNFhmR1NUR97OzCZpIm/+NgodteDHip4kyUqfY58ERU 8nwNjCEq5VfKBiG0/hiX6RgP54iDQboMD4pxwJ4nAgji4ZiZedPTONkx+HGAfIiQcPnf sq0A== X-Gm-Message-State: AIVw112mqmeX6n1dJ1oN13BdTBCV2kNsxLGMaUb+03748gLHK9FhNnie 9tYzCbNVGUBoLw== X-Received: by 10.37.119.142 with SMTP id s136mr17423737ybc.232.1500307271749; Mon, 17 Jul 2017 09:01:11 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:fb48]) by smtp.googlemail.com with ESMTPSA id s64sm5989564ywg.4.2017.07.17.09.01.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jul 2017 09:01:11 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] combine move assign/ctor check Message-ID: Date: Mon, 17 Jul 2017 12:01:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 We currently have separate 'has-move-assign' and 'has-move-ctor' functions. but they are always called together. so lets just have a single 'has-move-assign-or-move-ctor' function. Applied to trunk. nathan 2017-07-17 Nathan Sidwell * class.c (type_has_user_declared_move_constructor, type_has_user_declared_move_assign): Combine into ... (classtype_has_user_move_assign_or_move_ctor_p): ... this new function. * cp-tree.h (type_has_user_declared_move_constructor, type_has_user_declared_move_assign): Combine into ... (classtype_has_user_move_assign_or_move_ctor_p): ... this. Declare. * method.c (maybe_explain_implicit_delete): Use it. (lazily_declare_fn): Use it. * tree.c (type_has_nontrivial_copy_init): Use it. Index: cp/class.c =================================================================== --- cp/class.c (revision 250272) +++ cp/class.c (working copy) @@ -5491,48 +5491,30 @@ type_has_move_assign (tree t) return false; } -/* Returns true iff class T has a move constructor that was explicitly - declared in the class body. Note that this is different from - "user-provided", which doesn't include functions that are defaulted in - the class. */ +/* Returns true iff T, a class, has a user-declared move-assignment or + move-constructor. Note that this is different from + "user-provided", which doesn't include functions that are defaulted + in the class. */ bool -type_has_user_declared_move_constructor (tree t) +classtype_has_user_move_assign_or_move_ctor_p (tree t) { - if (CLASSTYPE_LAZY_MOVE_CTOR (t)) - return false; - if (!CLASSTYPE_METHOD_VEC (t)) return false; - for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) - { - tree fn = *iter; - if (move_fn_p (fn) && !DECL_ARTIFICIAL (fn)) + if (!CLASSTYPE_LAZY_MOVE_CTOR (t)) + for (ovl_iterator iter (lookup_fnfields_slot_nolazy (t, ctor_identifier)); + iter; ++iter) + if (!DECL_ARTIFICIAL (*iter) && move_fn_p (*iter)) return true; - } - - return false; -} - -/* Returns true iff class T has a move assignment operator that was - explicitly declared in the class body. */ -bool -type_has_user_declared_move_assign (tree t) -{ - if (CLASSTYPE_LAZY_MOVE_ASSIGN (t)) - return false; - - for (ovl_iterator iter (lookup_fnfields_slot_nolazy - (t, cp_assignment_operator_id (NOP_EXPR))); - iter; ++iter) - { - tree fn = *iter; - if (move_fn_p (fn) && !DECL_ARTIFICIAL (fn)) + if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t)) + for (ovl_iterator iter (lookup_fnfields_slot_nolazy + (t, cp_assignment_operator_id (NOP_EXPR))); + iter; ++iter) + if (!DECL_ARTIFICIAL (*iter) && move_fn_p (*iter)) return true; - } - + return false; } Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 250272) +++ cp/cp-tree.h (working copy) @@ -6025,8 +6025,7 @@ extern bool type_has_constexpr_default_c extern bool type_has_virtual_destructor (tree); extern bool type_has_move_constructor (tree); extern bool type_has_move_assign (tree); -extern bool type_has_user_declared_move_constructor (tree); -extern bool type_has_user_declared_move_assign(tree); +extern bool classtype_has_user_move_assign_or_move_ctor_p (tree); extern bool type_build_ctor_call (tree); extern bool type_build_dtor_call (tree); extern void explain_non_literal_class (tree); Index: cp/method.c =================================================================== --- cp/method.c (revision 250272) +++ cp/method.c (working copy) @@ -1808,10 +1808,8 @@ maybe_explain_implicit_delete (tree decl informed = false; } else if (DECL_ARTIFICIAL (decl) - && (sfk == sfk_copy_assignment - || sfk == sfk_copy_constructor) - && (type_has_user_declared_move_constructor (ctype) - || type_has_user_declared_move_assign (ctype))) + && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor) + && classtype_has_user_move_assign_or_move_ctor_p (ctype)) { inform (DECL_SOURCE_LOCATION (decl), "%q#D is implicitly declared as deleted because %qT " @@ -2372,10 +2370,8 @@ lazily_declare_fn (special_function_kind /* [class.copy]/8 If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted.... */ - if ((sfk == sfk_copy_assignment - || sfk == sfk_copy_constructor) - && (type_has_user_declared_move_constructor (type) - || type_has_user_declared_move_assign (type))) + if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor) + && classtype_has_user_move_assign_or_move_ctor_p (type)) DECL_DELETED_FN (fn) = true; /* A destructor may be virtual. */ Index: cp/tree.c =================================================================== --- cp/tree.c (revision 250272) +++ cp/tree.c (working copy) @@ -3976,8 +3976,7 @@ type_has_nontrivial_copy_init (const_tre else if (CLASSTYPE_LAZY_COPY_CTOR (t)) { saw_copy = true; - if (type_has_user_declared_move_constructor (t) - || type_has_user_declared_move_assign (t)) + if (classtype_has_user_move_assign_or_move_ctor_p (t)) /* [class.copy]/8 If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted.... */;