On Mon, Jul 22, 2013 at 12:29 PM, Marshall Clow <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><div><div><div>On Jul 22, 2013, at 12:23 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><br><blockquote type="cite">
On Mon, Jul 22, 2013 at 12:05 PM, Marshall Clow <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
On Jul 22, 2013, at 11:59 AM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>> wrote:<br>
<br>
> On Mon, Jul 22, 2013 at 11:22 AM, Marshall Clow <<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>> wrote:<br>
>> I'm trying to implement N3642 in libc++ (User-defined literals for standard library types) and I'm running into something I don't understand.<br>
>><br>
>> I tried to implement them in a standalone program, and got errors from clang:<br>
>>> string_literal.cpp:6:21: warning: user-defined literal suffixes not starting<br>
>>> with '_' are reserved; no literal will invoke this operator<br>
>><br>
>> Ok, fine. I developed my (and tested my code) using underscores. That all works (see attached "string_literal.cpp")<br>
>><br>
>> [ All the code here was built with TOT clang and "-std=c++1y -stdlib=libc++ -I $LLVM/libcxx/include" ]<br>
>><br>
>> Then I dropped the code into libc++'s <string> header and removed the underscores (patch attached).<br>
>> No warnings - so apparently clang can tell when the code is in a system header.<br>
><br>
> Yes... but it's probably just suppressing the warning, not actually<br>
> changing the behavior.<br>
><br>
>> But if I uncomment the code that uses those operators (starting about line 46 of string_literal.cpp), I get the following errors:<br>
>><br>
>>> string_literal.cpp:46:48: error: invalid suffix on literal; C++11 requires a<br>
>>> space between literal and identifier [-Wreserved-user-defined-literal]<br>
>>> static_assert ( std::is_same<decltype( "hi"s), std::string>::v...<br>
>>> ^<br>
>>><br>
>>> string_literal.cpp:46:48: error: expected ')'<br>
>>> string_literal.cpp:46:40: note: to match this '('<br>
>>> static_assert ( std::is_same<decltype( "hi"s), std::string>::v...<br>
>>> ^<br>
>>> string_literal.cpp:46:3: error: static_assert failed ""<br>
>>> static_assert ( std::is_same<decltype( "hi"s), std::string>::value, "...<br>
>>> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
>><br>
>> which, it seems to me, are just wrong.<br>
>><br>
>> Maybe I screwed up putting the stuff into <string> (but that looks ok to me).<br>
>> I thought I might be using the wrong set of libc++ header files, but I checked, and I don't think that's happening, either.<br></div></div></blockquote><div><br></div><div>That's not how it works -- it'd be a massive layering violation for the lexer to care about which names have been declared. See below.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
>><br>
>> Any suggestions?<br>
><br>
> User-defined literals without underscores are reserved... and so<br>
> without any guidance from the standard as to what they are supposed to<br>
> do, clang just ignores them outright.<br>
<br>
</div></div>Um, I don't think that's right.<br>
<br>
They are reserved for standard library implementations, and the C++14 draft defines several such suffixes that library implementers must implement.</blockquote><div><br></div><div>Right. The lexer change to support UDLs breaks a large set of programs (including most users of the PRI* and SCN* macros added from C99 in C++11), so since all such suffixes were reserved in C++11, we chose to lex them as if in C++98 mode for compatibility. The intent was that once some standard suffixes were added, we would modify the lexer to treat those suffixes as UDL suffixes; we're not got around to doing that yet.</div>
<div><br></div><div>If you can provide a list of string suffixes that C++14 defines, it should be straightforward to teach the lexer to treat those ones as UDLs. I think it's just "s" we need to handle, but I've not checked.</div>
</div>
</blockquote><br></div></div></div><div>I think the full list is in N3642.</div><div><br></div><div><span style="white-space:pre-wrap"> </span>s (for seconds and string)</div><div><span style="white-space:pre-wrap"> </span>h (hours)</div>
<div><span style="white-space:pre-wrap"> </span>min (minutes)</div><div><span style="white-space:pre-wrap"> </span>ms, us, ns (milliseconds, microseconds and nanoseconds)</div><div><br></div><div>Note that the complex ones (i, il, i_f) were NOT voted in.</div>
</div></blockquote><div><br></div><div>OK, these should work in -std=c++1y, as of r186933.</div></div>