From patchwork Wed Dec 5 13:32:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Smith-Rowland <3dw4rd@verizon.net> X-Patchwork-Id: 203871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 755B92C00B4 for ; Thu, 6 Dec 2012 00:32:39 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355319162; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-id:Date:From:User-Agent:MIME-version:To:Subject: Content-type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=wgkWbJO /xeVkaG7eqYR+aRPoEoc=; b=BMmCvmuWVMSTZ09AzM3tzbBs3+j1kX9Aw3ZBvD/ T1fZR35fV8rTobQOJnoB0mgFVWfJjzPC7XHQrVTIFEMXHYH/4OnnKeo3oiwR5QHx ucR9GjTmYfchay3kGOaCr1izLUEODOvi34BbVCH08nyo0ycn1QqV/kgmi93703wu X25w= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-id:Date:From:User-Agent:MIME-version:To:Subject:Content-type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=tlDn1ADrMDjPB+2njatXGVFZYzCTr/ysZL174/KHjzmvvf3tjSaVPJjbiJF9oL GAk6DcvmUrSxP2P+JcztnJuUw9rqnRPZHRP6hOcbCU7roYiEuinVnGwcxxIgNkaI ag1EcusMpk9rwNF69485kKIQbJpLJK2M7sk732hOq74H4=; Received: (qmail 18752 invoked by alias); 5 Dec 2012 13:32:33 -0000 Received: (qmail 18740 invoked by uid 22791); 5 Dec 2012 13:32:32 -0000 X-SWARE-Spam-Status: No, hits=3.8 required=5.0 tests=AWL, BAYES_00, BOTNET, HDRS_LCASE, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, T_MANY_HDRS_LCASE X-Spam-Check-By: sourceware.org Received: from vms173013pub.verizon.net (HELO vms173013pub.verizon.net) (206.46.173.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 05 Dec 2012 13:32:26 +0000 Received: from [192.168.1.8] ([unknown] [96.244.95.109]) by vms173013.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0MEK0023T89DRO80@vms173013.mailsrvcs.net> for gcc-patches@gcc.gnu.org; Wed, 05 Dec 2012 07:32:02 -0600 (CST) Message-id: <50BF4CD3.3020203@verizon.net> Date: Wed, 05 Dec 2012 08:32:03 -0500 From: Ed Smith-Rowland <3dw4rd@verizon.net> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-version: 1.0 To: gcc-patches Subject: [PATCH][C++11][ PR55582] Let string literals starting with lower-case 's' be a user-defined literal instead of string + macro. Content-type: multipart/mixed; boundary=------------080809080607040901080301 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 There is a proposal to add several user-defined literals to the standard library that looks like it will probably go through: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3468.pdf The proposed string literals std::string hw = "Hello, world!"s; will not parse as a literal in gcc. This patch fixes this by modifying the lexing of "string"XYZ user-defined literals as *two* tokens if the suffix starts with a letter *unless the letter is a lower-case 's'*. i.e. don't parse as a user-defined literal but as a sequence of string and macro *unless starts with lower case 's'*. The original code parsed all string literals with suffix beginning with any letter as a sequence of string and macro (two tokens, not one). Thanks, gcc/libcpp/ 2012-12-05 Ed Smith-Rowland <3dw4rd@verizon.net> PR c++/55582 * lex.c (lex_raw_string): Allow string literal with suffix starting with lower-case 's' as a user-defined literal. (lex_string): Ditto. gcc/testsuite/ 2012-12-05 Ed Smith-Rowland <3dw4rd@verizon.net> PR c++/55582 * g++.dg/cpp0x/udlit-string-literal.h: New. * g++.dg/cpp0x/udlit-string-literal.C: New. Index: libcpp/lex.c =================================================================== --- libcpp/lex.c (revision 194178) +++ libcpp/lex.c (working copy) @@ -1562,8 +1562,10 @@ from inttypes.h, we generate a warning and treat the ud-suffix as a separate preprocessing token. This approach is under discussion by the standards committee, and has been adopted as a conforming - extension by other front ends such as clang. */ - if (ISALPHA (*cur)) + extension by other front ends such as clang. + A special exception is made for the suffix 's' which will be + standardized as a user-defined literal suffix for strings. */ + if (ISALPHA (*cur) && *cur != 's') { /* Raise a warning, but do not consume subsequent tokens. */ if (CPP_OPTION (pfile, warn_literal_suffix)) @@ -1573,7 +1575,7 @@ "a space between literal and identifier"); } /* Grab user defined literal suffix. */ - else if (*cur == '_') + else if (ISIDST (*cur)) { type = cpp_userdef_string_add_type (type); ++cur; @@ -1693,8 +1695,10 @@ from inttypes.h, we generate a warning and treat the ud-suffix as a separate preprocessing token. This approach is under discussion by the standards committee, and has been adopted as a conforming - extension by other front ends such as clang. */ - if (ISALPHA (*cur)) + extension by other front ends such as clang. + A special exception is made for the suffix 's' which will be + standardized as a user-defined literal suffix for strings. */ + if (ISALPHA (*cur) && *cur != 's') { /* Raise a warning, but do not consume subsequent tokens. */ if (CPP_OPTION (pfile, warn_literal_suffix)) @@ -1704,7 +1708,7 @@ "a space between literal and identifier"); } /* Grab user defined literal suffix. */ - else if (*cur == '_') + else if (ISIDST (*cur)) { type = cpp_userdef_char_add_type (type); type = cpp_userdef_string_add_type (type); Index: gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C (revision 0) @@ -0,0 +1,12 @@ +// { dg-options "-std=c++11" } +// PR c++/55582 + +#include "udlit-string-literal.h" + +using namespace my_string_literals; + +decltype("Hello, World!"s) s; +decltype(u8"Hello, World!"s) s8; +decltype(L"Hello, World!"s) ws; +decltype(u"Hello, World!"s) s16; +decltype(U"Hello, World!"s) s32; Index: gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h =================================================================== --- gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h (revision 0) @@ -0,0 +1,22 @@ +#pragma GCC system_header + +#include + +inline namespace my_string_literals +{ + std::string + operator"" s(const char* str, std::size_t len) + { return std::string{str, len}; } + + std::wstring + operator"" s(const wchar_t* str, std::size_t len) + { return std::wstring{str, len}; } + + std::u16string + operator"" s(const char16_t* str, std::size_t len) + { return std::u16string{str, len}; } + + std::u32string + operator"" s(const char32_t* str, std::size_t len) + { return std::u32string{str, len}; } +}