diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4981462ccc962a128089679d21a39279fa5d00fb..e4f70ceeef0218ee73ed5ac5bdc482bb996b47ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2013-02-13 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. + 2013-02-13 Sriraman Tallam <tmsriram@google.com> * g++.dg/ext/mv12-aux.C: Add directives to match mv12.C. diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C new file mode 100644 index 0000000000000000000000000000000000000000..f83bef68ad33f2114b5e3269cf3e338e7b99bba5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C @@ -0,0 +1,13 @@ +// { dg-options "-std=c++11" } +// { dg-require-effective-target stdint_types } +// 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; diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h new file mode 100644 index 0000000000000000000000000000000000000000..e61034ec4ef5e807f816ee2fa69b150b708253ec --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h @@ -0,0 +1,22 @@ +#pragma GCC system_header + +#include <string> + +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}; } +} diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index aa6a02d91f9cc59640913d8a0fbb3f364e989c18..22451a2103f71dbbf284c748b13f815304bdde90 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,9 @@ +2013-02-13 Ed Smith-Rowland <3dw4rd@verizon.net> + + PR c++/55582 + * libcpp/lex.c (lex_raw_string): Allow string literal with suffix + beginning with 's' to be parsed as a C++11 user-defined literal. + 2013-01-14 Richard Sandiford <rdsandiford@googlemail.com> Update copyright years. diff --git a/libcpp/lex.c b/libcpp/lex.c index aa87da95323149fc0d516d02bda3d7dbdbb9daac..976d9e8b0eb72f761ee394112ecc9de704276ab6 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1561,8 +1561,10 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base, 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)) @@ -1572,7 +1574,7 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base, "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; @@ -1692,8 +1694,10 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base) 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)) @@ -1703,7 +1707,7 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base) "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);