blob: d121e25ba27076b8dd09333c7ce666995fa406e2 [file] [log] [blame]
Marshall Clowca0be232013-07-23 17:05:24 +00001// -*- 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//===----------------------------------------------------------------------===//
Asiri Rathnayake6edc12c2016-05-28 08:57:35 +000010
11// UNSUPPORTED: c++98, c++03, c++11
12
Marshall Clowca0be232013-07-23 17:05:24 +000013#include <string>
14#include <cassert>
15
16int main()
17{
Marshall Clowca0be232013-07-23 17:05:24 +000018 using namespace std::literals::string_literals;
19
Howard Hinnantd0987132013-08-07 19:39:48 +000020 static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" );
21 static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" );
22 static_assert ( std::is_same<decltype( L"Hi"s), std::wstring>::value, "" );
23 static_assert ( std::is_same<decltype( u"Hi"s), std::u16string>::value, "" );
24 static_assert ( std::is_same<decltype( U"Hi"s), std::u32string>::value, "" );
Eric Fiselierd04c6852016-06-01 21:35:39 +000025
Howard Hinnantd0987132013-08-07 19:39:48 +000026 std::string foo;
27 std::wstring Lfoo;
28 std::u16string ufoo;
29 std::u32string Ufoo;
Eric Fiselierd04c6852016-06-01 21:35:39 +000030
Howard Hinnantd0987132013-08-07 19:39:48 +000031 foo = ""s; assert( foo.size() == 0);
32 foo = u8""s; assert( foo.size() == 0);
33 Lfoo = L""s; assert(Lfoo.size() == 0);
34 ufoo = u""s; assert(ufoo.size() == 0);
35 Ufoo = U""s; assert(Ufoo.size() == 0);
Eric Fiselierd04c6852016-06-01 21:35:39 +000036
Howard Hinnantd0987132013-08-07 19:39:48 +000037 foo = " "s; assert( foo.size() == 1);
38 foo = u8" "s; assert( foo.size() == 1);
39 Lfoo = L" "s; assert(Lfoo.size() == 1);
40 ufoo = u" "s; assert(ufoo.size() == 1);
41 Ufoo = U" "s; assert(Ufoo.size() == 1);
Eric Fiselierd04c6852016-06-01 21:35:39 +000042
Howard Hinnantd0987132013-08-07 19:39:48 +000043 foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC"));
44 foo = u8"ABC"s; assert( foo == u8"ABC"); assert( foo == std::string (u8"ABC"));
45 Lfoo = L"ABC"s; assert(Lfoo == L"ABC"); assert(Lfoo == std::wstring ( L"ABC"));
46 ufoo = u"ABC"s; assert(ufoo == u"ABC"); assert(ufoo == std::u16string( u"ABC"));
47 Ufoo = U"ABC"s; assert(Ufoo == U"ABC"); assert(Ufoo == std::u32string( U"ABC"));
Marshall Clowca0be232013-07-23 17:05:24 +000048}