[cfe-dev] literal suffixes for std::basic_string?

Marshall Clow mclow.lists at gmail.com
Mon Jul 22 11:22:58 PDT 2013


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.

I tried to implement them in a standalone program, and got errors from clang:
> string_literal.cpp:6:21: warning: user-defined literal suffixes not starting
>       with '_' are reserved; no literal will invoke this operator

Ok, fine. I developed my (and tested my code) using underscores. That all works (see attached "string_literal.cpp")

[ All the code here was built with TOT clang and "-std=c++1y -stdlib=libc++ -I $LLVM/libcxx/include"  ]

Then I dropped the code into libc++'s <string> header and removed the underscores (patch attached).
No warnings - so apparently clang can tell when the code is in a system header.

But if I uncomment the code that uses those operators (starting about line 46 of string_literal.cpp), I get the following errors:

> string_literal.cpp:46:48: error: invalid suffix on literal; C++11 requires a
>       space between literal and identifier [-Wreserved-user-defined-literal]
>         static_assert ( std::is_same<decltype(   "hi"s), std::string>::v...
>                                                      ^
>                                                       
> string_literal.cpp:46:48: error: expected ')'
> string_literal.cpp:46:40: note: to match this '('
>         static_assert ( std::is_same<decltype(   "hi"s), std::string>::v...
>                                              ^
> string_literal.cpp:46:3: error: static_assert failed ""
>         static_assert ( std::is_same<decltype(   "hi"s), std::string>::value, "...
>         ^               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

which, it seems to me, are just wrong.

Maybe I screwed up putting the stuff into <string> (but that looks ok to me).
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.

Any suggestions?

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists at gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki
-------------- next part --------------
A non-text attachment was scrubbed...
Name: string_literal.cpp
Type: application/octet-stream
Size: 1810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130722/5468c032/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: string_lit.patch
Type: application/octet-stream
Size: 1670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130722/5468c032/attachment-0001.obj>


More information about the cfe-dev mailing list