blob: 65ebb3c509ec6e820de725fa6d950c352790561c [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
Marshall Clow289f1ce2018-11-20 22:55:40 +000016#include "test_macros.h"
17
Marshall Clowca0be232013-07-23 17:05:24 +000018int main()
19{
Marshall Clowca0be232013-07-23 17:05:24 +000020 using namespace std::literals::string_literals;
21
Howard Hinnantd0987132013-08-07 19:39:48 +000022 static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" );
Marshall Clow289f1ce2018-11-20 22:55:40 +000023// This is changed by P0482 to return a std::u8string
24#if TEST_STD_VER <= 17
Howard Hinnantd0987132013-08-07 19:39:48 +000025 static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" );
Marshall Clow289f1ce2018-11-20 22:55:40 +000026#endif
Howard Hinnantd0987132013-08-07 19:39:48 +000027 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, "" );
Eric Fiselierd04c6852016-06-01 21:35:39 +000030
Howard Hinnantd0987132013-08-07 19:39:48 +000031 std::string foo;
32 std::wstring Lfoo;
33 std::u16string ufoo;
34 std::u32string Ufoo;
Eric Fiselierd04c6852016-06-01 21:35:39 +000035
Howard Hinnantd0987132013-08-07 19:39:48 +000036 foo = ""s; assert( foo.size() == 0);
Marshall Clow289f1ce2018-11-20 22:55:40 +000037// This is changed by P0482 to return a std::u8string
38#if TEST_STD_VER <= 17
Howard Hinnantd0987132013-08-07 19:39:48 +000039 foo = u8""s; assert( foo.size() == 0);
Marshall Clow289f1ce2018-11-20 22:55:40 +000040#endif
Howard Hinnantd0987132013-08-07 19:39:48 +000041 Lfoo = L""s; assert(Lfoo.size() == 0);
42 ufoo = u""s; assert(ufoo.size() == 0);
43 Ufoo = U""s; assert(Ufoo.size() == 0);
Eric Fiselierd04c6852016-06-01 21:35:39 +000044
Howard Hinnantd0987132013-08-07 19:39:48 +000045 foo = " "s; assert( foo.size() == 1);
Marshall Clow289f1ce2018-11-20 22:55:40 +000046// This is changed by P0482 to return a std::u8string
47#if TEST_STD_VER <= 17
Howard Hinnantd0987132013-08-07 19:39:48 +000048 foo = u8" "s; assert( foo.size() == 1);
Marshall Clow289f1ce2018-11-20 22:55:40 +000049#endif
Howard Hinnantd0987132013-08-07 19:39:48 +000050 Lfoo = L" "s; assert(Lfoo.size() == 1);
51 ufoo = u" "s; assert(ufoo.size() == 1);
52 Ufoo = U" "s; assert(Ufoo.size() == 1);
Eric Fiselierd04c6852016-06-01 21:35:39 +000053
Howard Hinnantd0987132013-08-07 19:39:48 +000054 foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC"));
Marshall Clow289f1ce2018-11-20 22:55:40 +000055// This is changed by P0482 to return a std::u8string
56#if TEST_STD_VER <= 17
Howard Hinnantd0987132013-08-07 19:39:48 +000057 foo = u8"ABC"s; assert( foo == u8"ABC"); assert( foo == std::string (u8"ABC"));
Marshall Clow289f1ce2018-11-20 22:55:40 +000058#endif
Howard Hinnantd0987132013-08-07 19:39:48 +000059 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"));
Marshall Clowca0be232013-07-23 17:05:24 +000062}