From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8590 invoked by alias); 20 Sep 2011 20:16:14 -0000 Received: (qmail 8581 invoked by uid 22791); 20 Sep 2011 20:16:12 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Sep 2011 20:15:53 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8KKFrdp020244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 20 Sep 2011 16:15:53 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p8KKFq34017651; Tue, 20 Sep 2011 16:15:52 -0400 Received: from [0.0.0.0] (ovpn-113-145.phx2.redhat.com [10.3.113.145]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p8KKFoYI026088; Tue, 20 Sep 2011 16:15:51 -0400 Message-ID: <4E78F475.8070303@redhat.com> Date: Tue, 20 Sep 2011 21:48:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: Ed Smith-Rowland <3dw4rd@verizon.net> CC: gcc-patches Subject: Re: [C++-11] User defined literals References: <4E6F6A1C.90305@verizon.net> <4E7008DA.6090703@redhat.com> <4E76FBBB.6050601@verizon.net> <4E77B002.50804@redhat.com> <4E77F549.6000704@verizon.net> In-Reply-To: <4E77F549.6000704@verizon.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg01192.txt.bz2 On 09/19/2011 10:07 PM, Ed Smith-Rowland wrote: > On 09/19/2011 05:11 PM, Jason Merrill wrote: >> Can't you store the string and the suffix, and then interpret the >> number later if you end up calling an operator that takes the value? > I could and I thought abut it but from the wording (2.14.8 p3 and p4) it > looks like the numeric argument gets first try, then raw literal then > literal template. I thought I might as well let the preprocessor do the > numeric conversion since I'll always check it first. Fair enough. We could do the overload resolution before we produce the actual value to be passed, but I guess that's probably not a sufficient optmization to bother with. > + error ("user-defined literal operator template %q+D" > + " conflicts with user-defined raw literal operator %q+D", > + newdecl, olddecl); You should only use + for one of the decls; that sets the source position for the diagnostic. > + TK(CHAR_USERDEF, LITERAL) /* 'char'_suffix - C++-0x */ \ > + TK(WCHAR_USERDEF, LITERAL) /* L'char'_suffix - C++-0x */ \ > + TK(CHAR16_USERDEF, LITERAL) /* u'char'_suffix - C++-0x */ \ > + TK(CHAR32_USERDEF, LITERAL) /* U'char'_suffix - C++-0x */ \ > + TK(STRING_USERDEF, LITERAL) /* "string"_suffix - C++-0x */ \ > + TK(WSTRING_USERDEF, LITERAL) /* L"string"_suffix - C++-0x */ \ > + TK(STRING16_USERDEF, LITERAL) /* u"string"_suffix - C++-0x */ \ > + TK(STRING32_USERDEF, LITERAL) /* U"string"_suffix - C++-0x */ \ > + TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */ \ Could we avoid adding all these additional codes by setting a flag on the token? It seems odd to have extra codes for char/string literals but not for numbers. > + const char *suffix; > + cpp_get_userdef_suffix (tok->val.str, '\'', &suffix); Let's return the suffix pointer instead of passing in the address of a local variable. And pass in the token pointer rather than the string and a delimiter; libcpp can figure out which delimiter to use based on the token type. It could also handle the flag I suggested above so that the front end doesn't need to know about it. Jason