From patchwork Fri Aug 26 07:35:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp117092wro; Fri, 26 Aug 2022 00:36:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4pc6JxdIyYW6tVJDWmA5C9LyCNLXJh5HgTIlU+PQiCL5zPXO8XoRuf363TEvnNhvbX75DY X-Received: by 2002:a05:6402:1f8c:b0:43e:8fab:76c with SMTP id c12-20020a0564021f8c00b0043e8fab076cmr5804507edc.126.1661499370098; Fri, 26 Aug 2022 00:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661499370; cv=none; d=google.com; s=arc-20160816; b=saWKd9ud/WMvj6fgVYmTkpOEoRimUCA5NbBgC6vIwgcXtT+NHkJxm1kV2t/WPIlqf0 LPJmVQ4vHiBKTpmS95sg/EQ1YHCcK8xfgwVmhZqGigVL1GiYeYX5efEf8NZOGsOj13gi I1QpKPOrxI9G/scxaQfMbquqAkiZ45JQ1uogYZtCMPZvH1ASWrGReeksBrzF2b9J7ZbX r1OI7ReA1+RlbG/M3j5dQAqmiFfCjyzCqadflsfX0VLFiGSi+JCb2OWmFMAk04kvMR5v ySiY43y3rbMjsA6nlGXHYtWaKcSWyJM3ld1RXDaNX2ABFnWHiTuCTnBRhnByzh+Un8jz 2xAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:content-disposition:mime-version :message-id:subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=rRPXL/avZ5QvSmohmQpsKNdhvAxT0apgudDgp/i7KRQ=; b=d2+vPsMNjA/xvtvoEff44UfxLT2FpYbqpGnxYsSZThaRhe2l5s6dWJmQhdPI7GTf2a fRBFmd/ntIWxY2zP7PmlYFUG/Ihi4Xmo+7744WZG7qfiUnggOyVnrx6elkcGRz1KK7UL 1NjkNrYAb/tuOvfKkYSERgI02USIvUkllFf02ElbRv3cekiGDrnCbn0P0fwz03DCe7YK GYq7OW6S8SkgCWCz91kdQjab7HK6UlFfLgdsbjazeYKOJwLMvTtvT4c8ONeAnuApMboc kiTRiy6Nf5jPWABpTRZx1/q1d82cz/Wm0BIR/CkXYJbbPiFHfTFvLXRG7/tfuePLV6Jc qyiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QD1jlO7D; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w10-20020a056402070a00b0044669239f34si974576edx.213.2022.08.26.00.36.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 00:36:10 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=QD1jlO7D; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C30C382DA4F for ; Fri, 26 Aug 2022 07:36:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C30C382DA4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661499369; bh=rRPXL/avZ5QvSmohmQpsKNdhvAxT0apgudDgp/i7KRQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QD1jlO7D3U90A4xV39+0ozL4DR5E/faW0PJ2EQ3Ps6+hxUqS/er6rdq/sxwAdiZLx DpeBRLqDJQnlh6/aCqKqjjYWjbZ90RxTRxVPZPLOGLEr1BSRfukTb4pfFWZswFr6l3 sLJNhf82jjIpiYa0+gJBHKxPzeEEKAHQgPUJ+RVU= 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 D82C63858004 for ; Fri, 26 Aug 2022 07:35:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D82C63858004 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-88-Y4TV6teVODSzgI6w0b84RA-1; Fri, 26 Aug 2022 03:35:23 -0400 X-MC-Unique: Y4TV6teVODSzgI6w0b84RA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B9FF1C05ABE for ; Fri, 26 Aug 2022 07:35:23 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B38118EA8; Fri, 26 Aug 2022 07:35:22 +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 27Q7ZK2N222399 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 26 Aug 2022 09:35:20 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27Q7ZKOZ222398; Fri, 26 Aug 2022 09:35:20 +0200 Date: Fri, 26 Aug 2022 09:35:19 +0200 To: Jason Merrill Subject: [PATCH] libcpp: Implement P2362R3 - Remove non-encodable wide character literals and multicharacter [PR106647] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742208363908903966?= X-GMAIL-MSGID: =?utf-8?q?1742208363908903966?= Hi! My understanding of the paper is that we just want to promote the CPP_WCHAR "character constant too long for its type" warning to error as it is already error for u8, u and U literals. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-08-26 Jakub Jelinek PR c++/106647 * charset.cc (wide_str_to_charconst): Implement P2362R3 - Remove non-encodable wide character literals and multicharacter. For C++23 use CPP_DL_ERROR instead of CPP_DL_WARNING for "character constant too long for its type" diagnostics on CPP_WCHAR literals. * g++.dg/cpp23/wchar-multi1.C: New test. * g++.dg/cpp23/wchar-multi2.C: New test. Jakub --- libcpp/charset.cc.jj 2022-08-25 11:54:38.849924475 +0200 +++ libcpp/charset.cc 2022-08-25 18:36:20.650415220 +0200 @@ -2170,7 +2170,11 @@ wide_str_to_charconst (cpp_reader *pfile character constant is guaranteed to overflow. */ if (str.len > nbwc * 2) cpp_error (pfile, (CPP_OPTION (pfile, cplusplus) - && (type == CPP_CHAR16 || type == CPP_CHAR32)) + && (type == CPP_CHAR16 + || type == CPP_CHAR32 + /* In C++23 this is error even for L'ab'. */ + || (type == CPP_WCHAR + && CPP_OPTION (pfile, size_t_literals)))) ? CPP_DL_ERROR : CPP_DL_WARNING, "character constant too long for its type"); --- gcc/testsuite/g++.dg/cpp23/wchar-multi1.C.jj 2022-08-25 18:08:01.973426155 +0200 +++ gcc/testsuite/g++.dg/cpp23/wchar-multi1.C 2022-08-25 18:51:30.476687112 +0200 @@ -0,0 +1,42 @@ +// P2362R3 - Remove non-encodable wide character literals and multicharacter +// wide character literals. +// { dg-do compile } + +char a = 'a'; +int b = 'ab'; // { dg-warning "multi-character character constant" } +int c = '\u05D9'; // { dg-warning "multi-character character constant" } +#if __SIZEOF_INT__ > 2 +int d = '\U0001F525'; // { dg-warning "multi-character character constant" "" { target int32 } } +#endif +int e = 'abcd'; // { dg-warning "multi-character character constant" } +wchar_t f = L'f'; +wchar_t g = L'gh'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } +wchar_t h = L'ijkl'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } +wchar_t i = L'\U0001F525'; // { dg-error "character constant too long for its type" "" { target { c++23 && { ! 4byte_wchar_t } } } } + // { dg-warning "character constant too long for its type" "" { target { c++20_down && { ! 4byte_wchar_t } } } .-1 } +#ifdef __cpp_char8_t +typedef char8_t u8; +#else +typedef char u8; +#endif +#if __cpp_unicode_characters >= 201411 +u8 j = u8'j'; +u8 k = u8'kl'; // { dg-error "character constant too long for its type" "" { target c++17 } } +u8 l = u8'\U0001F525'; // { dg-error "character constant too long for its type" "" { target c++17 } } +#endif +#if __cpp_unicode_characters >= 200704 +char16_t m = u'm'; +char16_t n = u'no'; // { dg-error "character constant too long for its type" "" { target c++11 } } +char16_t o = u'\u05D9'; +char16_t p = u'\U0001F525'; // { dg-error "character constant too long for its type" "" { target c++11 } } +char32_t q = U'm'; +char32_t r = U'no'; // { dg-error "character constant too long for its type" "" { target c++11 } } +char32_t s = U'\u05D9'; +char32_t t = U'\U0001F525'; +#endif +wchar_t u = L'\u0065\u0301'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } +wchar_t v = L'é'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } --- gcc/testsuite/g++.dg/cpp23/wchar-multi2.C.jj 2022-08-25 18:51:53.744386945 +0200 +++ gcc/testsuite/g++.dg/cpp23/wchar-multi2.C 2022-08-25 18:53:03.317489442 +0200 @@ -0,0 +1,43 @@ +// P2362R3 - Remove non-encodable wide character literals and multicharacter +// wide character literals. +// { dg-do compile } +// { dg-options "-fshort-wchar" } + +char a = 'a'; +int b = 'ab'; // { dg-warning "multi-character character constant" } +int c = '\u05D9'; // { dg-warning "multi-character character constant" } +#if __SIZEOF_INT__ > 2 +int d = '\U0001F525'; // { dg-warning "multi-character character constant" "" { target int32 } } +#endif +int e = 'abcd'; // { dg-warning "multi-character character constant" } +wchar_t f = L'f'; +wchar_t g = L'gh'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } +wchar_t h = L'ijkl'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } +wchar_t i = L'\U0001F525'; // { dg-error "character constant too long for its type" "" { target { c++23 } } } + // { dg-warning "character constant too long for its type" "" { target { c++20_down } } .-1 } +#ifdef __cpp_char8_t +typedef char8_t u8; +#else +typedef char u8; +#endif +#if __cpp_unicode_characters >= 201411 +u8 j = u8'j'; +u8 k = u8'kl'; // { dg-error "character constant too long for its type" "" { target c++17 } } +u8 l = u8'\U0001F525'; // { dg-error "character constant too long for its type" "" { target c++17 } } +#endif +#if __cpp_unicode_characters >= 200704 +char16_t m = u'm'; +char16_t n = u'no'; // { dg-error "character constant too long for its type" "" { target c++11 } } +char16_t o = u'\u05D9'; +char16_t p = u'\U0001F525'; // { dg-error "character constant too long for its type" "" { target c++11 } } +char32_t q = U'm'; +char32_t r = U'no'; // { dg-error "character constant too long for its type" "" { target c++11 } } +char32_t s = U'\u05D9'; +char32_t t = U'\U0001F525'; +#endif +wchar_t u = L'\u0065\u0301'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 } +wchar_t v = L'é'; // { dg-error "character constant too long for its type" "" { target c++23 } } + // { dg-warning "character constant too long for its type" "" { target c++20_down } .-1 }