From patchwork Mon Apr 29 15:21:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1092650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499851-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HMsHICf1"; dkim-atps=neutral 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 44t7g74zCLz9sDQ for ; Tue, 30 Apr 2019 01:21:53 +1000 (AEST) Received: (qmail 35026 invoked by alias); 29 Apr 2019 15:21:47 -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 35018 invoked by uid 89); 29 Apr 2019 15:21:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=ptc, UD:pt.c, pt.c, sk:contain X-HELO: mail-pl1-f170.google.com Received: from mail-pl1-f170.google.com (HELO mail-pl1-f170.google.com) (209.85.214.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Apr 2019 15:21:45 +0000 Received: by mail-pl1-f170.google.com with SMTP id f36so5227552plb.5 for ; Mon, 29 Apr 2019 08:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=5ZqDbfXtTh31r6Ley+YpfilCU0sVrqSJkF/2dS9g394=; b=HMsHICf1cg0C3Xx8PwtR8EaiyJpoksM8a/sLkcwHn1C+Tp1fbJ3p2uBE1cFxtyUXXr YtaJ5chLQiUZRzsdIrKKxbfJZ+6JmWLst59/NDEoYXwQ9zzOOdBTJeL3Bh5lzEMIImMN 2BZB6HyZfIobANWMD778J5cJpqk8xdxgoLH8Fv67iXtPu1PSxWqod8IbYp66fqkWxQJY wYEAE5Hyei7zH2i2W3sagmefVnp57aiOgXbJubMJinFsgu7ZDzeSMjNDh90XQaDCjvEa vYuEZvZU4AEC84Vcu5x6zYPTdPIvQ1qHaV+oEcC1qvzq3Rqpd4SVamQfldAeVpvto/99 gJfQ== Received: from ?IPv6:2620:10d:c0a3:1407:7c8a:7933:8a4d:8c40? ([2620:10d:c091:200::3:eeda]) by smtp.googlemail.com with ESMTPSA id d67sm38803626pfa.35.2019.04.29.08.21.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 08:21:43 -0700 (PDT) Sender: Nathan Sidwell To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] some cleanups Message-ID: <50f312a9-7e49-35f2-4aac-2ceffee55561@acm.org> Date: Mon, 29 Apr 2019 11:21:41 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 This patch fixes some formatting and code clarity issues I've tripped over in the past few months. duplicate_decls has some function- and var- specific behaviour that was confusingly commented, and, for the var case mixed the checking for var with checking for the flag to copy. process_outer_var_ref had some unnecessary line-breaks and block scopes. explain_implicit_non_constexpr had some unnecessary repetitiveness. Applying to trunk. nathan 2019-04-29 Nathan Sidwell * decl.c (duplicate_decls): Add whitespace, move comments into conditional blocks. * method.c (explain_implicit_non_constexpr): Refactor. * pt.c (check_explicit_specialization): Fix indentation. * semantics.c (process_outer_var_ref): Reformat. (finish_id_expression_1): Use STRIP_TEMPLATE. Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 270651) +++ gcc/cp/decl.c (working copy) @@ -1,4 +1,4 @@ -/* Process declarations and variables for C++ compiler. +/* Process declarations and variables for -*- C++ -*- compiler. Copyright (C) 1988-2019 Free Software Foundation, Inc. Contributed by Michael Tiemann (tiemann@cygnus.com) @@ -1476,7 +1476,7 @@ duplicate_decls (tree newdecl, tree oldd if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2))) break; -next_arg:; + next_arg:; } warning_at (newdecl_loc, @@ -2386,9 +2386,10 @@ next_arg:; } DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); } - /* Only functions have these fields. */ + if (DECL_DECLARES_FUNCTION_P (newdecl)) { + /* Only functions have these fields. */ DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); DECL_BEFRIENDING_CLASSES (newdecl) = chainon (DECL_BEFRIENDING_CLASSES (newdecl), @@ -2398,10 +2399,12 @@ next_arg:; if (DECL_VIRTUAL_P (newdecl)) SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl)); } - /* Only variables have this field. */ - else if (VAR_P (newdecl) - && VAR_HAD_UNKNOWN_BOUND (olddecl)) - SET_VAR_HAD_UNKNOWN_BOUND (newdecl); + else if (VAR_P (newdecl)) + { + /* Only variables have this field. */ + if (VAR_HAD_UNKNOWN_BOUND (olddecl)) + SET_VAR_HAD_UNKNOWN_BOUND (newdecl); + } } if (TREE_CODE (newdecl) == FUNCTION_DECL) Index: gcc/cp/method.c =================================================================== --- gcc/cp/method.c (revision 270651) +++ gcc/cp/method.c (working copy) @@ -1884,15 +1884,14 @@ maybe_explain_implicit_delete (tree decl void explain_implicit_non_constexpr (tree decl) { - tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl)); - bool const_p = CP_TYPE_CONST_P (non_reference (parm_type)); + tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl); + bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms))); tree inh = DECL_INHERITED_CTOR (decl); bool dummy; synthesized_method_walk (DECL_CLASS_CONTEXT (decl), special_function_p (decl), const_p, NULL, NULL, NULL, &dummy, true, - &inh, - FUNCTION_FIRST_USER_PARMTYPE (decl)); + &inh, parms); } /* DECL is an instantiation of an inheriting constructor template. Deduce Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 270651) +++ gcc/cp/pt.c (working copy) @@ -3026,7 +3026,7 @@ check_explicit_specialization (tree decl `operator T'. Grab all the conversion operators, and then select from them. */ tree fns = get_class_binding (ctype, IDENTIFIER_CONV_OP_P (name) - ? conv_op_identifier : name); + ? conv_op_identifier : name); if (fns == NULL_TREE) { Index: gcc/cp/semantics.c =================================================================== --- gcc/cp/semantics.c (revision 270651) +++ gcc/cp/semantics.c (working copy) @@ -3482,16 +3482,12 @@ process_outer_var_ref (tree decl, tsubst /* A lambda in an NSDMI (c++/64496). */ break; - if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) - == CPLD_NONE) + if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE) break; - lambda_stack = tree_cons (NULL_TREE, - lambda_expr, - lambda_stack); + lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack); - containing_function - = decl_function_context (containing_function); + containing_function = decl_function_context (containing_function); } /* In a lambda within a template, wait until instantiation time to implicitly @@ -3502,8 +3498,7 @@ process_outer_var_ref (tree decl, tsubst && DECL_PACK_P (decl)) return decl; - if (lambda_expr && VAR_P (decl) - && DECL_ANON_UNION_VAR_P (decl)) + if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl)) { if (complain & tf_error) error ("cannot capture member %qD of anonymous union", decl); @@ -3512,11 +3507,8 @@ process_outer_var_ref (tree decl, tsubst /* Do lambda capture when processing the id-expression, not when odr-using a variable. */ if (!odr_use && context == containing_function) - { - decl = add_default_capture (lambda_stack, - /*id=*/DECL_NAME (decl), - initializer); - } + decl = add_default_capture (lambda_stack, + /*id=*/DECL_NAME (decl), initializer); /* Only an odr-use of an outer automatic variable causes an error, and a constant variable can decay to a prvalue constant without odr-use. So don't complain yet. */ @@ -3528,8 +3520,7 @@ process_outer_var_ref (tree decl, tsubst { error ("%qD is not captured", decl); tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr); - if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) - == CPLD_NONE) + if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE) inform (location_of (closure), "the lambda has no capture-default"); else if (TYPE_CLASS_SCOPE_P (closure)) @@ -3844,10 +3835,11 @@ finish_id_expression_1 (tree id_expressi } else if (is_overloaded_fn (decl)) { + /* We only need to look at the first function, + because all the fns share the attribute we're + concerned with (all member fns or all non-members). */ tree first_fn = get_first_fn (decl); - - if (TREE_CODE (first_fn) == TEMPLATE_DECL) - first_fn = DECL_TEMPLATE_RESULT (first_fn); + first_fn = STRIP_TEMPLATE (first_fn); /* [basic.def.odr]: "A function whose name appears as a potentially-evaluated expression is odr-used if it is the unique