[cfe-dev] hexfloats in c++0x
Douglas Gregor
dgregor at apple.com
Thu Feb 10 10:04:20 PST 2011
On Jan 29, 2011, at 10:01 PM, Johannes Schaub (litb) wrote:
> Douglas Gregor wrote:
>
>>
>> On Jan 27, 2011, at 10:50 AM, Howard Hinnant wrote:
>>
>>> Can we turn on support for hexfloats in -std=c++0x? It is already turned
>>> on in c++03 mode.
>>>
>>> get_double.pass.cpp:108:14: error: invalid suffix 'p' on integer constant
>>> assert(v == 0x125p-1);
>>> ^
>>
>> They're disabled in C++0x mode because they conflict with user-defined
>> literals. We might be able to jump through some hoops to see if there's a
>> literal operator named "p" or "P" in scope, but... yuck.
>>
>> Suggestions welcome!
>>
>
> I think that behavior is undefined for any program that uses a literal
> suffix without a leading underscore, because those names are reserved for
> use by a further Standard.
The *library* reserves those names, not the language. The language is perfectly happy to allow operator ""p, and that's where the conflict with C99 comes up.
> Therefor, I think clang's lexer could just prefer lexing "0x123p4" as a
> floating point literal and can issue a warning about declarations of names
> such as 'operator "" p' ("warning: literal operator will never be used
> implicitly" or some such).
Yes, of course we can do that. It's a hack that assumes that the user is going to use the standard library somewhere, and therefore falls under the rule that prohibits user-defined literal operators without a leading "_".
- Doug
More information about the cfe-dev
mailing list