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++98, 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 24 int main() 25 { 26 using namespace std::literals::string_literals; 27 28 static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" ); 29 static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" ); 30 static_assert ( std::is_same<decltype( L"Hi"s), std::wstring>::value, "" ); 31 static_assert ( std::is_same<decltype( u"Hi"s), std::u16string>::value, "" ); 32 static_assert ( std::is_same<decltype( U"Hi"s), std::u32string>::value, "" ); 33 34 std::string foo; 35 std::wstring Lfoo; 36 u8string u8foo; 37 std::u16string ufoo; 38 std::u32string Ufoo; 39 40 foo = ""s; assert( foo.size() == 0); 41 u8foo = u8""s; assert(u8foo.size() == 0); 42 Lfoo = L""s; assert( Lfoo.size() == 0); 43 ufoo = u""s; assert( ufoo.size() == 0); 44 Ufoo = U""s; assert( Ufoo.size() == 0); 45 46 foo = " "s; assert( foo.size() == 1); 47 u8foo = u8" "s; assert(u8foo.size() == 1); 48 Lfoo = L" "s; assert( Lfoo.size() == 1); 49 ufoo = u" "s; assert( ufoo.size() == 1); 50 Ufoo = U" "s; assert( Ufoo.size() == 1); 51 52 foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC")); 53 u8foo = u8"ABC"s; assert(u8foo == u8"ABC"); assert(u8foo == u8string (u8"ABC")); 54 Lfoo = L"ABC"s; assert( Lfoo == L"ABC"); assert( Lfoo == std::wstring ( L"ABC")); 55 ufoo = u"ABC"s; assert( ufoo == u"ABC"); assert( ufoo == std::u16string( u"ABC")); 56 Ufoo = U"ABC"s; assert( Ufoo == U"ABC"); assert( Ufoo == std::u32string( U"ABC")); 57 } 58