1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++03, c++11
11 
12 #include <string>
13 #include <cassert>
14 
15 #include "test_macros.h"
16 
17 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
18     typedef std::u8string u8string;
19 #else
20     typedef std::string   u8string;
21 #endif
22 
23 int main(int, char**) {
24     {
25         using namespace std::literals::string_literals;
26 
27         ASSERT_SAME_TYPE(decltype(  "Hi"s), std::string);
28         ASSERT_SAME_TYPE(decltype(u8"Hi"s), u8string);
29         ASSERT_SAME_TYPE(decltype( L"Hi"s), std::wstring);
30         ASSERT_SAME_TYPE(decltype( u"Hi"s), std::u16string);
31         ASSERT_SAME_TYPE(decltype( U"Hi"s), std::u32string);
32 
33         std::string foo;
34         std::wstring Lfoo;
35         u8string u8foo;
36         std::u16string ufoo;
37         std::u32string Ufoo;
38 
39         foo   =   ""s;     assert(  foo.size() == 0);
40         u8foo = u8""s;     assert(u8foo.size() == 0);
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         u8foo = u8" "s;    assert(u8foo.size() == 1);
47         Lfoo  =  L" "s;    assert( Lfoo.size() == 1);
48         ufoo  =  u" "s;    assert( ufoo.size() == 1);
49         Ufoo  =  U" "s;    assert( Ufoo.size() == 1);
50 
51         foo   =   "ABC"s;     assert(  foo ==   "ABC");   assert(  foo == std::string   (  "ABC"));
52         u8foo = u8"ABC"s;     assert(u8foo == u8"ABC");   assert(u8foo == u8string      (u8"ABC"));
53         Lfoo  =  L"ABC"s;     assert( Lfoo ==  L"ABC");   assert( Lfoo == std::wstring  ( L"ABC"));
54         ufoo  =  u"ABC"s;     assert( ufoo ==  u"ABC");   assert( ufoo == std::u16string( u"ABC"));
55         Ufoo  =  U"ABC"s;     assert( Ufoo ==  U"ABC");   assert( Ufoo == std::u32string( U"ABC"));
56     }
57     {
58         using namespace std::literals;
59         std::string foo = ""s;
60         assert(foo == std::string());
61     }
62     {
63         using namespace std;
64         std::string foo = ""s;
65         assert(foo == std::string());
66     }
67 
68     return 0;
69 }
70