1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 // UNSUPPORTED: c++98, c++03, c++11
12 
13 #include <string>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 
18 int main()
19 {
20     using namespace std::literals::string_literals;
21 
22     static_assert ( std::is_same<decltype(   "Hi"s), std::string>::value, "" );
23 //	This is changed by P0482 to return a std::u8string
24 #if TEST_STD_VER <= 17
25     static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" );
26 #endif
27     static_assert ( std::is_same<decltype(  L"Hi"s), std::wstring>::value, "" );
28     static_assert ( std::is_same<decltype(  u"Hi"s), std::u16string>::value, "" );
29     static_assert ( std::is_same<decltype(  U"Hi"s), std::u32string>::value, "" );
30 
31     std::string foo;
32     std::wstring Lfoo;
33     std::u16string ufoo;
34     std::u32string Ufoo;
35 
36     foo  =   ""s;     assert( foo.size() == 0);
37 //	This is changed by P0482 to return a std::u8string
38 #if TEST_STD_VER <= 17
39     foo  = u8""s;     assert( foo.size() == 0);
40 #endif
41     Lfoo =  L""s;     assert(Lfoo.size() == 0);
42     ufoo =  u""s;     assert(ufoo.size() == 0);
43     Ufoo =  U""s;     assert(Ufoo.size() == 0);
44 
45     foo  =   " "s;     assert( foo.size() == 1);
46 //	This is changed by P0482 to return a std::u8string
47 #if TEST_STD_VER <= 17
48     foo  = u8" "s;     assert( foo.size() == 1);
49 #endif
50     Lfoo =  L" "s;     assert(Lfoo.size() == 1);
51     ufoo =  u" "s;     assert(ufoo.size() == 1);
52     Ufoo =  U" "s;     assert(Ufoo.size() == 1);
53 
54     foo  =   "ABC"s;     assert( foo ==   "ABC");   assert( foo == std::string   (  "ABC"));
55 //	This is changed by P0482 to return a std::u8string
56 #if TEST_STD_VER <= 17
57     foo  = u8"ABC"s;     assert( foo == u8"ABC");   assert( foo == std::string   (u8"ABC"));
58 #endif
59     Lfoo =  L"ABC"s;     assert(Lfoo ==  L"ABC");   assert(Lfoo == std::wstring  ( L"ABC"));
60     ufoo =  u"ABC"s;     assert(ufoo ==  u"ABC");   assert(ufoo == std::u16string( u"ABC"));
61     Ufoo =  U"ABC"s;     assert(Ufoo ==  U"ABC");   assert(Ufoo == std::u32string( U"ABC"));
62 }
63