From patchwork Tue Nov 28 08:22:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 170600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3760674vqx; Tue, 28 Nov 2023 00:22:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVhzMHlQjDgwDKsVj2+ME7/Z7RXaTqiaL4PTuwSE9DOZ9qcQfMrWKwXnYllQQUcwlbK4av X-Received: by 2002:a25:870c:0:b0:da0:d0be:ef06 with SMTP id a12-20020a25870c000000b00da0d0beef06mr12595182ybl.51.1701159766251; Tue, 28 Nov 2023 00:22:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701159766; cv=pass; d=google.com; s=arc-20160816; b=BVS3tHRC+q6wF5DwGyOk2dj0DSKYHrrGiNGGFsXUPGulpsdhoMi2oDAj9m42kLJh7R Rzlxs7AOlVe6L+XyZJWV41Vnwv0ssdyhIa44llQF544DnGyz6y0o5l3i/a1qH9xZetCY n4SCdL9LE23N7OAVaL89cWrEZ51v1UuA0lcAxugfCQIwRnoTGFbiiOphsvxO63xbP/xI yXLPKkdyheGc5VAaBYB0Ok/Gyi0XaEk1oFVn1z6BOBsciixXUCg++MSl++P/0To/Pa6n nlOtUkd8PfFRwqVrR5N8LvjA1QwDkp3UtAd+EV5p8B8F0uw9q9V9dKOIYRBL9GkgNMXe ccpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=YRm/rQD1XlAArGIYRZ3JhCuKhtbe+WyN2Bu+7arv000=; fh=iS+SrUA7/3KenGc+sXDHcUIclYKa8cqUMVweghTnk54=; b=tJrvLeoTvrtg8NGhAJAWuQ2Fx7LdDOWPzI+g/SU2NM1qhjBk+mqCvv1B7EHMYIJaQT 1JH3IkWdP/33bRFofmF4rRm0hkmyMPg6JYGuur6aBd1Oi/kK0xFmk0L4oHtVOkqSvgPu VjE8AOBfkZLxU//v47TZuBG0aOLYk6m5ZlcFv9/yQ3Exyi9r+EmBWdF5DtF1Nle9+vyc mk4YChgTGBL7w0ZC0GI+rnfBTqhQPlCWefsIbP6+Twm42ajYo5Y1t7AZ4pNr4FODUX+C 5ParjqylWoGnfm+bpwlqLfER5Xj2qwDznpsuH9YTisAugXz9hcBJCdShslUdQF94u5zc H0gg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5qMFFnv; 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 c8-20020ac85a88000000b0041b83912a5dsi11249462qtc.187.2023.11.28.00.22.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:22:46 -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=h5qMFFnv; 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 0B02C3857BB1 for ; Tue, 28 Nov 2023 08:22:46 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 4F64B3858C39 for ; Tue, 28 Nov 2023 08:22:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F64B3858C39 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 4F64B3858C39 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=1701159742; cv=none; b=xgZLYZ4WEY1FrxclWgy34Z8ZLYB2OU//Wb50lc1nXR+pdImD+dLPmISh2JQBDZg8kNgprYza6aQvU0Vb5rnWaOErO7QSc3uU6X8EMJefW39t7CYT9Xs9JgdfI/5Mvqg7fB+t4lVQF4aLAiwm7BE7dEnsRsV9vTOSGuixlZ9rN5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701159742; c=relaxed/simple; bh=zXp+im8qhR7MlNN3mfht1COejEEDQomUWEl/E8yVYE4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=GIkcMEPiWdxag9bnCgb9Ch4XshR64t04z4gC8OClIMW7hJz1otPst1548q6gdfk2hacTXUKh2mIOD1Y3DjOzAkBGczxUloQPL1PoApLymOMIcgbExNu5iSj5xmCNNI6aaZU3ssP+dw0KXENYdovgHQFtTJ0UWUX1SJ3ceVfoQJ0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701159740; h=from:from:reply-to: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=YRm/rQD1XlAArGIYRZ3JhCuKhtbe+WyN2Bu+7arv000=; b=h5qMFFnvFY+N+ywWRWa38UlgVmozl2DohTrM/fXkO8xw9w/LnsuXCQ5m9B8fUZ8stXjkVY A7+oDuzy42iM2LbhnLoDuag7Yu0zY1jwQcn+E7jbdUAOYDQp9/h6Ock5Z9guwxDSwDieL2 5Ag7kCej5nj1r2tqmRjiIG1A+GegbB0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-9ngP_9nVPYSMokbLk2U03Q-1; Tue, 28 Nov 2023 03:22:19 -0500 X-MC-Unique: 9ngP_9nVPYSMokbLk2U03Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A04188D043; Tue, 28 Nov 2023 08:22:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B70791C060B0; Tue, 28 Nov 2023 08:22:18 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AS8MGNv487744 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Nov 2023 09:22:16 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AS8MFQj487743; Tue, 28 Nov 2023 09:22:15 +0100 Date: Tue, 28 Nov 2023 09:22:15 +0100 From: Jakub Jelinek To: Jason Merrill , Alex Coplan Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up __has_extension (cxx_init_captures) Message-ID: References: <54f7dafb-e8cf-4282-a042-a4abcba6494f@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783795303096149719 X-GMAIL-MSGID: 1783795303096149719 On Mon, Nov 27, 2023 at 10:58:04AM +0000, Alex Coplan wrote: > Many thanks both for the reviews, this is now pushed (with Jason's > above changes implemented) as g:06280a906cb3dc80cf5e07cf3335b758848d488d. The new test FAILs everywhere with GXX_TESTSUITE_STDS=98,11,14,17,20,2b I'm normally using for testing. FAIL: g++.dg/ext/has-feature.C -std=gnu++11 (test for excess errors) Excess errors: /home/jakub/src/gcc/gcc/testsuite/g++.dg/ext/has-feature.C:185:2: error: #error This is on #if __has_extension (cxx_init_captures) != CXX11 #error #endif Comparing the values with clang++ on godbolt and with what is actually implemented: void foo () { auto a = [b = 3]() { return b; }; } both clang++ and GCC implement init captures as extension already in C++11 (and obviously not in C++98 because lambdas aren't implemented there), unless -pedantic-errors/-Werror=pedantic, so I think we should change the FE to match the test rather than the other way around. Tested on x86_64-linux with GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-g++ RUNTESTFLAGS="--target_board=unix\{-m32,-m64\} dg.exp='has-feature.C'" Ok for trunk? Making __has_extension return __has_feature for -pedantic-errors and not for -Werror=pedantic is just weird, but as that is what clang++ implements and this is for compatibility with it, I can live with it (but perhaps we should mention it in the documentation). Note, the warnings/errors can be changed using pragmas inside of the source, so whether one can use an extension or not depends on where in the code it is (__extension__ to the rescue if it can be specified around it). I wonder if the has-feature.C test shouldn't be #included in other 2 tests, one where -pedantic-errors would be in dg-options and through some macro tell the file that __has_extension will behave like __has_feature, and another with -Werror=pedantic to document that the option doesn't change it. 2023-11-28 Jakub Jelinek * cp-objcp-common.cc (cp_feature_table): Evaluate __has_extension (cxx_init_captures) to 1 even for -std=c++11. Jakub --- gcc/cp/cp-objcp-common.cc.jj 2023-11-27 17:34:25.000000000 +0100 +++ gcc/cp/cp-objcp-common.cc 2023-11-28 08:55:18.868419864 +0100 @@ -145,7 +145,7 @@ static constexpr cp_feature_info cp_feat { "cxx_contextual_conversions", { cxx14, cxx98 } }, { "cxx_decltype_auto", cxx14 }, { "cxx_aggregate_nsdmi", cxx14 }, - { "cxx_init_captures", cxx14 }, + { "cxx_init_captures", { cxx14, cxx11 } }, { "cxx_generic_lambdas", cxx14 }, { "cxx_relaxed_constexpr", cxx14 }, { "cxx_return_type_deduction", cxx14 },