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 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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 }, Jakub