From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7981E3858C98 for ; Thu, 4 Apr 2024 18:43:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7981E3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7981E3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712256219; cv=none; b=rmQSgIRHKph76Ka7T0TdAjJdk66ar6ez4kV703T4EkiA7Rz4yY6r1PdUsVwcVpdV1n5mpjfL9jetyKZ57TEk1Uhs7xPvuLbgUN+H6Ei/vQcrXuH7leio/Y8fBq6OujaO9szB67a4tUtZm+WUKtDH+y2xyuds+ixOYqqjHK0t2uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712256219; c=relaxed/simple; bh=xXw1VAQfprszNFBQMM86Zf6Q6SSWmwR53h4ZgUmwt2I=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Aex8Z1Cy+5sU1bBbbbKMIeE/LONpn8fh8BNKDSJxrEyzlXrPBtKSjb7GV7y+oaaJOPJfVc5aEG3+UMWiOLX7y0oR9kXwjbL2QhprU2hKowJuUH464PxoruV1y5+DMc0ommdjSz4kjRbBUNcZekAJM5dN2QIhzdUGlQjMAUFBdmU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712256218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SUsRPd0gpWcgoFeb2ClBuSJAMw+nTHHwEdR2ZUH7guo=; b=apVK5+HT6s2IS+iqxl7oNOi9P+j0A7NJxz/W2PUIZ/D0jstVQD6tHMErxQU2xHBkYx3h0P E3wdl9IfRxmrqGH5VhR0lhqZdcz1KaXQg6bM6yrVIDMWIUf6h+VyDZem/RNj0oCXmN4zAH /2GJclXcrGamFksMVQ3hHlU28nKObfQ= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-8FpMLWSKNT6jE_Ls4LJpPQ-1; Thu, 04 Apr 2024 14:43:36 -0400 X-MC-Unique: 8FpMLWSKNT6jE_Ls4LJpPQ-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-43114d0421fso13855731cf.3 for ; Thu, 04 Apr 2024 11:43:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712256216; x=1712861016; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SUsRPd0gpWcgoFeb2ClBuSJAMw+nTHHwEdR2ZUH7guo=; b=uG2sQuA6E37jV11Sxf7X7cOvvzbHH5sO4HN0L3vVma8/3QpwCNpaPfkdeJyWa6iHXi j1kOrLzDoE5peHsHYEQYuUKqBhajIz49fxMsdvJKZmOOq2I9Q6YRaB75Nt6wph1bQGj3 umHB7ImjTmHwgeegB8Q7qJofsbCA6tvik5pLgisY9t0C7NEjM/A9vnvI/yY38OGx8HAs +eCOiYr2AkbKevMxdALjZCvi9SuB/74iiKDa/i7IDN2heMWnbsXTVCI01lw0YNcUUPSh qNpq+hranPT9DFlwM+pGXoKnx4yXZPBnk3OmH7ggmWzjPKEF67Y/9Nuqez5K9TdeXVcF QTYw== X-Gm-Message-State: AOJu0YzmVkaZnI/i+LjWffbb9dXVgKWB3Ho3EqlQ3uGuI5K3I5AmLyXg SM5CO+ooN/x8XPpf2udyXYWNH4rJX1IImkMo491vy44kqAUzM65xegn+1JIWx6BDr/2UW44oKsN lUMdx0B9cqIKA0G7QAp8lcbbvBteByhQ2CgGxQZ/iQ9eTXWwc2FLnY5w= X-Received: by 2002:a05:622a:1711:b0:434:504f:3254 with SMTP id h17-20020a05622a171100b00434504f3254mr2453441qtk.16.1712256215893; Thu, 04 Apr 2024 11:43:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPFXTJ/DupEK/WgySmiqHEZ5yi3pi2UMvBHKVaimMhZsv/+0pJFxYq40C8sbWz4+QS+hDttQ== X-Received: by 2002:a05:622a:1711:b0:434:504f:3254 with SMTP id h17-20020a05622a171100b00434504f3254mr2453422qtk.16.1712256215507; Thu, 04 Apr 2024 11:43:35 -0700 (PDT) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id fx7-20020a05622a4ac700b00430b60698e9sm7897918qtb.32.2024.04.04.11.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 11:43:34 -0700 (PDT) Date: Thu, 4 Apr 2024 14:43:33 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches , Jakub Jelinek Subject: Re: [PATCH] c++: constexpr error with fn redecl in local scope [PR111132] Message-ID: References: <20240402175237.482119-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, Apr 03, 2024 at 01:14:46PM -0400, Jason Merrill wrote: > On 4/2/24 13:52, Marek Polacek wrote: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13? > > > > -- >8 -- > > We evaluate constexpr functions on the original, pre-genericization bodies. > > That means that the function body we're evaluating will not have gone > > through cp_genericize_r's "Map block scope extern declarations to visible > > declarations with the same name and type in outer scopes if any". Here: > > > > constexpr bool bar() { return true; } // #1 > > constexpr bool foo() { > > constexpr bool bar(void); // #2 > > return bar(); > > } > > > > it means that we: > > 1) register_constexpr_fundef (#1) > > 2) cp_genericize (#1) > > nothing interesting happens > > 3) register_constexpr_fundef (foo) > > does copy_fn, so we have two copies of the BIND_EXPR > > 4) cp_genericize (foo) > > this remaps #2 to #1, but only on one copy of the BIND_EXPR > > 5) retrieve_constexpr_fundef (foo) > > we find it, no problem > > 6) retrieve_constexpr_fundef (#2) > > and here #2 isn't found in constexpr_fundef_table, because > > we're working on the BIND_EXPR copy where #2 wasn't mapped to #1 > > so we fail. We've only registered #1. > > > > It should work to use DECL_LOCAL_DECL_ALIAS (which used to be > > extern_decl_map). We evaluate constexpr functions on pre-cp_fold > > bodies to avoid diagnostic problems, but the remapping I'm proposing > > should not interfere with diagnostics. > > > > This is not a problem for a global scope redeclaration; there we go > > through duplicate_decls which keeps the DECL_UID: > > DECL_UID (olddecl) = olddecl_uid; > > and DECL_UID is what constexpr_fundef_hasher::hash uses. > > > > PR c++/111132 > > > > gcc/cp/ChangeLog: > > > > * constexpr.cc (get_function_named_in_call): If there's > > a DECL_LOCAL_DECL_ALIAS, use it. > > Perhaps this function should use cp_get_fndecl_from_callee, and this change > should be made there instead? It doesn't seem that get_function_named_in_call can use cp_get_fndecl_from_callee, (or be replaced with cp_get_callee_fndecl_nofold). We can get e.g. a CALL_EXPR whose CALL_EXPR_FN is a TEMPLATE_ID_EXPR, and get_function_named_in_call returns the TEMPLATE_ID_EXPR whereas cp_get_fndecl_from_callee would return null: if (TREE_CODE (fn) == FUNCTION_DECL) return fn; tree type = TREE_TYPE (fn); if (type == NULL_TREE || !INDIRECT_TYPE_P (type)) return NULL_TREE; Marek