From patchwork Fri Jan 19 19:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 189661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1242749dyb; Fri, 19 Jan 2024 11:40:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvjMk9kelxDxpU3KA12Cb+NGPHFMZixYvxkrZLOvddus+uEAt9QEbUbMAvWVpIoKtViVGv X-Received: by 2002:ac8:5acb:0:b0:429:e39e:56c1 with SMTP id d11-20020ac85acb000000b00429e39e56c1mr384022qtd.44.1705693215975; Fri, 19 Jan 2024 11:40:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705693215; cv=pass; d=google.com; s=arc-20160816; b=DRbVD7NEBP/dULcBytq1T1+p8RxQgM+MTT+2yE3moLCnFy+I18v8cE37qBE38M0KOx CQDb08CkT5oUewtpWg+fFeH2xj0HPKnT8qMPlL4rwhF8JcHbA0k9muU9ppFKuNCPxMrM LHOASPdMKICMMDTQ2xNEKEsvbDHGYlWFlGB62mQa69rue5lQDr5ttN+flY1OGqq/cZuB Y2WF9ao10mhSX+Yl2jn+7XMt0mxgx2UfkCrDauNZdDw8qUZuh8LsB6Qd4pLKMi/zg/B8 lqCX3rRZr8s6ePe/H0P8QulNa8X1do4YN1nMlsN19k9er/rQixPTuO/s4MwHiwBFSE+l zhpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=W+MW7l2KSfievffLb5rAMRi4qhREvE+uhQaD+gJ+Zeg=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=M8KVNqxkyQqgMmHGyNLXsTvLarpgzP2BXl+JPhwIdL61hzwjD9HL0mjx2m7z8h+VLJ w7nnSEbWseUanNPmqfUTRhoG+/m4RdRCey2yYLtuU5MucysoRtGOnkT94pIakJwQRNt7 CAkmA6ctQBSd+mwvmKD5QDTNuMLPgoOEvd/O58QHZT1FRKyJBSzg/KTRYJrvzJNItn+W i3hS5LamyHmj4mBj1Qr/uvlBfykBtaECki8ow2DZFSi5eO4TuEPMnE7lZm/hX6p/yW9I zzyUo3wQxdz8qAdnHxm/lbHCUy/qA7JTXwo+UFXDHrcshWQWjKYg8vkmSuENSUFb9GK3 Klng== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f2D5P5YD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r12-20020a05622a034c00b0042a14e98334si5334984qtw.552.2024.01.19.11.40.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 11:40:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f2D5P5YD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 932013857438 for ; Fri, 19 Jan 2024 19:40:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 709A43858C2D for ; Fri, 19 Jan 2024 19:39:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 709A43858C2D 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 709A43858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705693172; cv=none; b=vBdgprFYlN9P6FtrTd9ZQBgbP7ByQsDmT1a+416y3LxK5sfK1y9x6x29ZhI2k3YiA8fKfidcHrNeQfki1e4IQBjGEXq7hiJ63PVNHflmCyOnIPAtu2xFB9U8boq+UvYEghNgtw7HfDBDzicsDph8UnVhNK/61C/ZnJ24K3QEXNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705693172; c=relaxed/simple; bh=jl3QWWpNEHigcoPEjfHbpownfkOLBehHbJ3Q8/wEVKI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=sPAxJDbDCbYcH5unUA4tnq9S4FfJdYxpnmcYXb3xAE11PQOzkZP+WMMbVLzBKBSRTwnQSShKkW2nDi0Bou4CBkPfNRc9MIQC+eYYicI1OUd8qidx66no28RgIN6pr+55B4TdwImME1Y+NHD3kmkvHE5BMvWfTlpI/5de0K/jUio= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705693170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=W+MW7l2KSfievffLb5rAMRi4qhREvE+uhQaD+gJ+Zeg=; b=f2D5P5YDUiHjUo4om1fh8pBBY3wnJf+mPZwTehfQgrxrAyJ0BAUYehuB62QqrPsAKJvZZG hhn6AuNDcvsqC6d+gRnuj2uVpxmgcdXO48eoCD9ZMvSlqrrbWteZIe+Pz6AN0GpsexAshT dWpQT+R0yOa3+iK47W/zOzF5MWi/m10= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-SvtBLbBFOIS5RXezCkwKoQ-1; Fri, 19 Jan 2024 14:23:04 -0500 X-MC-Unique: SvtBLbBFOIS5RXezCkwKoQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7830ab8fb5aso111711085a.2 for ; Fri, 19 Jan 2024 11:23:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705692183; x=1706296983; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W+MW7l2KSfievffLb5rAMRi4qhREvE+uhQaD+gJ+Zeg=; b=bfJyOT7ypxEmt7shxmTHLqhmVpKpto0ccAWpgvWAajLwiif6XlG7qO7xxRBM0EJc0P gupAnaTKih2BBJUJMXSlD7CsgNMUnZX0/wsxdIAic6YhDPbveFRl29fAFaNt0T0jL39X 8v6S5bGDTqY28DtZKUTVMJHQqjBIzEj7/UEIN7HQAs1b9nq6BxP3RDO8KcoF+rgKcm3S fjshdVnqxvmSe/iPWgfzrjsojgFcBGXpG19gl6aaSHp3n6BclvsCHwEw7VxaTK3rV8TQ zONXLLLNJp87nBoikLkzD4bo7ml45RBo3R/34WGLPnCIg2q0T478cv+tUKXOQWWpr+CX 4xyA== X-Gm-Message-State: AOJu0YzJR7MOLayzbzufz0ZR8GoH48aZ9NbCHf77bMERE8YsoQj07g+r fU76wquLXzTULpHc7uEUetzhyZNKyf0ZBEPLiyM9V0Cx7dEMexc/37qmX1YLV9Sedg+RFw3D01N tyhFAvN/7eZounoGY17NiP2xmqWAgE2fXdjHjWnFLVBqAZY9zaaIQZWIkAy8vjDxxfyAVFrB9O7 BHFZzlJ86pkh5mIW3SMeBaRsSAVxMAGI8trkU= X-Received: by 2002:a05:620a:cf2:b0:783:22a9:9cc1 with SMTP id c18-20020a05620a0cf200b0078322a99cc1mr326587qkj.95.1705692183006; Fri, 19 Jan 2024 11:23:03 -0800 (PST) X-Received: by 2002:a05:620a:cf2:b0:783:22a9:9cc1 with SMTP id c18-20020a05620a0cf200b0078322a99cc1mr326578qkj.95.1705692182615; Fri, 19 Jan 2024 11:23:02 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id u3-20020a05620a022300b0078346a208d8sm5964056qkm.17.2024.01.19.11.23.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 11:23:02 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: requires and using-decl [PR113498] Date: Fri, 19 Jan 2024 14:23:00 -0500 Message-Id: <20240119192300.3522583-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788548969596341848 X-GMAIL-MSGID: 1788548969596341848 Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- get_template_info was crashing because it assumed that any decl with DECL_LANG_SPECIFIC could use DECL_TEMPLATE_INFO. It's more complicated than that. PR c++/113498 gcc/cp/ChangeLog: * pt.cc (decl_template_info): New fn. (get_template_info): Use it. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-using4.C: New test. --- gcc/cp/pt.cc | 30 ++++++++++++++++++-- gcc/testsuite/g++.dg/cpp2a/concepts-using4.C | 24 ++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-using4.C base-commit: 631a922e5c8578a1c878b69f1651d482b661ef4a diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index fbbca469219..74013533b0f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -339,6 +339,32 @@ build_template_info (tree template_decl, tree template_args) return result; } +/* DECL_TEMPLATE_INFO, if applicable, or NULL_TREE. */ + +static tree +decl_template_info (const_tree decl) +{ + /* This needs to match template_info_decl_check. */ + if (DECL_LANG_SPECIFIC (decl)) + switch (TREE_CODE (decl)) + { + case FUNCTION_DECL: + if (DECL_THUNK_P (decl)) + break; + gcc_fallthrough (); + case VAR_DECL: + case FIELD_DECL: + case TYPE_DECL: + case CONCEPT_DECL: + case TEMPLATE_DECL: + return DECL_TEMPLATE_INFO (decl); + + default: + break; + } + return NULL_TREE; +} + /* Return the template info node corresponding to T, whatever T is. */ tree @@ -353,8 +379,8 @@ get_template_info (const_tree t) || TREE_CODE (t) == PARM_DECL) return NULL; - if (DECL_P (t) && DECL_LANG_SPECIFIC (t)) - tinfo = DECL_TEMPLATE_INFO (t); + if (DECL_P (t)) + tinfo = decl_template_info (t); if (!tinfo && DECL_IMPLICIT_TYPEDEF_P (t)) t = TREE_TYPE (t); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-using4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-using4.C new file mode 100644 index 00000000000..a39a7c0a8a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-using4.C @@ -0,0 +1,24 @@ +// PR c++/113498 +// { dg-do compile { target c++20 } } + +template +struct S_Base +{ + static constexpr int D = d; +}; + +template +struct S : public S_Base +{ + using S_Base::D; + constexpr void f() const + requires(D > 0) {} + +}; + +int main(int, char**) +{ + S<1> s; + s.f(); + return 0; +}