From patchwork Sat Nov 16 19:38:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1196195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513800-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XIwAwI27"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="QCeg0TEU"; 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 47FlrX5zVLz9sP3 for ; Sun, 17 Nov 2019 06:38:36 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=rrf /x8dp2gapjxBgcJsQwyLNR3XfRlH4qnAYAg5YaLYIwvggGiMXRDdQkTtopDnOMsT Widkqsybln52Ipx59Zq2BDYgPeUBcQh+GlHGeTV7RSt+3DU8JNuXqw6YfxShQeLX z9M1HGK73eRLo553JAyMckrB50Mh2hD0IdUo7EEk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=T92CxFp8D cUbYeK3uRIm4ZRedPw=; b=XIwAwI27x4CR1zAxeZ4XJ3/Dq6vfAIC1W5800eGq1 6qieik2aiYr2p3K+O/0BK2bNgpNu3asWKraIA958SFtkHZrjSw8DlVA1w9Eb34Z8 AVVvDGeOViJbEjnxJWpI0elDjqxFNPa2cyt6AJAvZTQj/dYbUaYdk0uZVWc6S8HV 04= Received: (qmail 12391 invoked by alias); 16 Nov 2019 19:38:29 -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 12382 invoked by uid 89); 16 Nov 2019 19:38:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=201811, 201803, regtest, cpp1y X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 16 Nov 2019 19:38:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573933106; 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: content-transfer-encoding:content-transfer-encoding; bh=+IlBWm+/mNJq3I5E+AwvHZ8FvPtiBzi2DcWmopeCago=; b=QCeg0TEU2VgsR4UNxh8YE+sEsW7c4UpjT/QIDbl8FEnSzkb0KhyiGsY3wVhSSIRAlayPU3 NnV/XQySqi9X+Ux8BKYUdgKY3BvnQxfyoCnqdq7RTamATDWz6pv3X9K1jMZPTAU0FllmgP CWcfW+FDu5lro3sLh0HLfqUgZPYEqs4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-6i6wTMW2POuRj3qIWrVrJg-1; Sat, 16 Nov 2019 14:38:23 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA99B1005500 for ; Sat, 16 Nov 2019 19:38:22 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AE2E5DA66; Sat, 16 Nov 2019 19:38:22 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id xAGJcKxg007439; Sat, 16 Nov 2019 20:38:20 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xAGJcIpf007438; Sat, 16 Nov 2019 20:38:18 +0100 Date: Sat, 16 Nov 2019 20:38:18 +0100 From: Jakub Jelinek To: Jason Merrill , Jonathan Wakely Cc: gcc-patches@gcc.gnu.org Subject: [C++20 PATCH] Implement P1920R1, Missing feature-test macros 2017-2019 Message-ID: <20191116193818.GR4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! This implements the core part of P1920R1, tested on x86_64-linux, ok for trunk if it passes full bootstrap/regtest? Jon, are you going to handle the libstdc++ side of this, assuming there is something still not done where we have the corresponding features implemented already? 2019-11-16 Jakub Jelinek Implement P1920R1, Missing feature-test macros 2017-2019. * c-cppbuiltin.c (c_cpp_builtins): Bump __cpp_init_captures and __cpp_generic_lambdas for -std=c++2a. Define __cpp_designated_initializers, __cpp_constexpr_in_decltype and __cpp_consteval for -std=c++2a. Remove a FIXME comment about __cpp_concepts for -std=c++2a. * g++.dg/cpp1z/feat-cxx1z.C: Only compile with -std=c++17. * g++.dg/cpp2a/feat-cxx2a.C: Adjust for P1920R1 changes. * g++.dg/cpp2a/desig15.C: New test. * g++.dg/cpp2a/lambda-pack-init3.C: New test. * g++.dg/cpp2a/lambda-generic6.C: New test. * g++.dg/cpp2a/consteval15.C: New test. Jakub --- gcc/c-family/c-cppbuiltin.c.jj 2019-11-13 19:13:15.490048963 +0100 +++ gcc/c-family/c-cppbuiltin.c 2019-11-16 18:30:02.338883062 +0100 @@ -952,8 +952,11 @@ c_cpp_builtins (cpp_reader *pfile) { /* Set feature test macros for C++14. */ cpp_define (pfile, "__cpp_return_type_deduction=201304L"); - cpp_define (pfile, "__cpp_init_captures=201304L"); - cpp_define (pfile, "__cpp_generic_lambdas=201304L"); + if (cxx_dialect <= cxx17) + { + cpp_define (pfile, "__cpp_init_captures=201304L"); + cpp_define (pfile, "__cpp_generic_lambdas=201304L"); + } if (cxx_dialect <= cxx14) cpp_define (pfile, "__cpp_constexpr=201304L"); cpp_define (pfile, "__cpp_decltype_auto=201304L"); @@ -990,7 +993,12 @@ c_cpp_builtins (cpp_reader *pfile) if (cxx_dialect > cxx17) { /* Set feature test macros for C++2a. */ + cpp_define (pfile, "__cpp_init_captures=201803L"); + cpp_define (pfile, "__cpp_generic_lambdas=201707L"); + cpp_define (pfile, "__cpp_designated_initializers=201707L"); + cpp_define (pfile, "__cpp_constexpr_in_decltype=201711L"); cpp_define (pfile, "__cpp_conditional_explicit=201806L"); + cpp_define (pfile, "__cpp_consteval=201811L"); cpp_define (pfile, "__cpp_constinit=201907L"); cpp_define (pfile, "__cpp_nontype_template_parameter_class=201806L"); cpp_define (pfile, "__cpp_impl_destroying_delete=201806L"); @@ -1000,7 +1008,6 @@ c_cpp_builtins (cpp_reader *pfile) if (flag_concepts) { if (cxx_dialect >= cxx2a) - /* FIXME: Update this to the value required by the IS. */ cpp_define (pfile, "__cpp_concepts=201907L"); else cpp_define (pfile, "__cpp_concepts=201507L"); --- gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C.jj 2019-10-19 09:22:15.756879262 +0200 +++ gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C 2019-11-16 18:34:08.045190225 +0100 @@ -1,5 +1,5 @@ -// { dg-do compile { target c++17 } } -// { dg-options "-I${srcdir}/g++.dg/cpp1y -I${srcdir}/g++.dg/cpp1y/testinc" } +// { dg-do compile } +// { dg-options "-std=c++17 -I${srcdir}/g++.dg/cpp1y -I${srcdir}/g++.dg/cpp1y/testinc" } // C++98 features: --- gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C.jj 2019-10-19 09:22:16.168872968 +0200 +++ gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C 2019-11-16 18:42:37.817528261 +0100 @@ -122,14 +122,14 @@ #ifndef __cpp_init_captures # error "__cpp_init_captures" -#elif __cpp_init_captures != 201304 -# error "__cpp_init_captures != 201304" +#elif __cpp_init_captures != 201803 +# error "__cpp_init_captures != 201803" #endif #ifndef __cpp_generic_lambdas # error "__cpp_generic_lambdas" -#elif __cpp_generic_lambdas != 201304 -# error "__cpp_generic_lambdas != 201304" +#elif __cpp_generic_lambdas != 201707 +# error "__cpp_generic_lambdas != 201707" #endif #ifndef __cpp_constexpr @@ -507,3 +507,27 @@ #elif __cpp_char8_t != 201811 # error "__cpp_char8_t != 201811" #endif + +#ifndef __cpp_designated_initializers +# error "__cpp_designated_initializers" +#elif __cpp_designated_initializers != 201707 +# error "__cpp_designated_initializers != 201707" +#endif + +#ifndef __cpp_constexpr_in_decltype +# error "__cpp_constexpr_in_decltype" +#elif __cpp_constexpr_in_decltype != 201711 +# error "__cpp_constexpr_in_decltype != 201711" +#endif + +#ifndef __cpp_consteval +# error "__cpp_consteval" +#elif __cpp_consteval != 201811 +# error "__cpp_consteval != 201811" +#endif + +#ifndef __cpp_concepts +# error "__cpp_concepts" +#elif __cpp_concepts != 201907 +# error "__cpp_concepts != 201907" +#endif --- gcc/testsuite/g++.dg/cpp2a/desig15.C.jj 2019-11-16 19:07:37.527982693 +0100 +++ gcc/testsuite/g++.dg/cpp2a/desig15.C 2019-11-16 19:09:25.630357282 +0100 @@ -0,0 +1,27 @@ +// { dg-do run } +// { dg-options "-pedantic" } + +struct A { int a; }; +struct B { int b; A c; int d; }; +A a = { 1 }; +B c = { 3, { 4 }, 5 }; +#if __cpp_designated_initializers >= 201707L +A b = { .a = 2 }; +B d = { .b = 6, .c { 7 }, .d = 8 }; +B e = { .c = { .a = 9 } }; +#else +A b = { 2 }; +B d = { 6, { 7 }, 8 }; +B e = { 0, { 9 } }; +#endif + +int +main () +{ + if (a.a != 1 || b.a != 2 + || c.b != 3 || c.c.a != 4 || c.d != 5 + || d.b != 6 || d.c.a != 7 || d.d != 8 + || e.b != 0 || e.c.a != 9 || e.d != 0) + __builtin_abort (); + return 0; +} --- gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C.jj 2019-11-16 19:05:00.170348712 +0100 +++ gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C 2019-11-16 19:06:34.101936361 +0100 @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +void bar(); +void bar(int); + +template +void foo(Args... args) { +#if __cpp_init_captures >= 201803 + auto f = [...xs=args]{ + bar(xs...); + }; +#endif +} + +int main() +{ + foo(); + foo(1); +} --- gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C.jj 2019-11-16 19:01:25.504576417 +0100 +++ gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C 2019-11-16 19:02:58.616176396 +0100 @@ -0,0 +1,11 @@ +// P0428R2 +// { dg-do compile { target c++14 } } + +struct S { int s; }; + +auto x = +#if __cpp_generic_lambdas >= 201707 + [](T &&t) { return t.s; } ({ 2 }); +#else + [](auto &&t) { return t.s; } (S { 2 }); +#endif --- gcc/testsuite/g++.dg/cpp2a/consteval15.C.jj 2019-11-16 19:12:50.352279212 +0100 +++ gcc/testsuite/g++.dg/cpp2a/consteval15.C 2019-11-16 19:12:44.631365186 +0100 @@ -0,0 +1,14 @@ +// { dg-do compile { target c++11 } } + +#if __cpp_consteval >= 201811L +consteval +#else +constexpr +#endif +int +foo (int x) +{ + return x * x * x * x; +} + +auto a = foo (2);