From 8d9dd7a968ce810c02c67c94a0eb9fbe5733d70b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 5 Oct 2013 21:18:32 +0000 Subject: [PATCH] Mark namespaces for user defined literals as 'inline' git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@192047 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/chrono | 14 ++--- include/string | 5 +- .../basic.string.literals/literal1.fail.cpp | 4 +- .../basic.string.literals/literal3.pass.cpp | 20 ++++++++ .../time.duration.literals/literals1.fail.cpp | 21 ++++++++ .../time.duration.literals/literals1.pass.cpp | 48 +++++++++++++++++ .../time.duration.literals/literals2.fail.cpp | 22 ++++++++ .../time.duration.literals/literals2.pass.cpp | 51 +++++++++++++++++++ 8 files changed, 173 insertions(+), 12 deletions(-) create mode 100644 test/strings/basic.string.literals/literal3.pass.cpp create mode 100644 test/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp create mode 100644 test/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp create mode 100644 test/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp create mode 100644 test/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp diff --git a/include/chrono b/include/chrono index afc51817..2c65eee7 100644 --- a/include/chrono +++ b/include/chrono @@ -942,12 +942,9 @@ typedef steady_clock high_resolution_clock; } // chrono -#if _LIBCPP_STD_VER > 11 -// Literal suffixes for chrono types -// inline // Deviation from N3690. -// We believe the inline to be a defect and have submitted an LWG issue. -// An LWG issue number has not yet been assigned. -namespace literals +#if _LIBCPP_STD_VER > 11 +// Suffixes for duration literals [time.duration.literals] +inline namespace literals { inline namespace chrono_literals { @@ -1018,6 +1015,11 @@ namespace literals } }} + +namespace chrono { // hoist the literals into namespace std::chrono + using namespace literals::chrono_literals; +} + #endif _LIBCPP_END_NAMESPACE_STD diff --git a/include/string b/include/string index 1ad81595..c98e22f0 100644 --- a/include/string +++ b/include/string @@ -4158,10 +4158,7 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* #if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] -// inline // Deviation from N3690. -// We believe the inline to be a defect and have submitted an LWG issue. -// An LWG issue number has not yet been assigned. -namespace literals +inline namespace literals { inline namespace string_literals { diff --git a/test/strings/basic.string.literals/literal1.fail.cpp b/test/strings/basic.string.literals/literal1.fail.cpp index 16641f2b..6ba0b30d 100644 --- a/test/strings/basic.string.literals/literal1.fail.cpp +++ b/test/strings/basic.string.literals/literal1.fail.cpp @@ -13,9 +13,9 @@ int main() { #if _LIBCPP_STD_VER > 11 - using namespace std; + using std::string; - std::string foo = ""s; // should fail w/conversion operator not found + string foo = ""s; // should fail w/conversion operator not found #else #error #endif diff --git a/test/strings/basic.string.literals/literal3.pass.cpp b/test/strings/basic.string.literals/literal3.pass.cpp new file mode 100644 index 00000000..98e3e40e --- /dev/null +++ b/test/strings/basic.string.literals/literal3.pass.cpp @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std; + + string foo = ""s; +#endif +} diff --git a/test/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp b/test/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp new file mode 100644 index 00000000..46aaa30e --- /dev/null +++ b/test/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp @@ -0,0 +1,21 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::chrono::hours h = 4h; // should fail w/conversion operator not found +#else +#error +#endif +} + diff --git a/test/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp b/test/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp new file mode 100644 index 00000000..574f9bcc --- /dev/null +++ b/test/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::chrono; + + hours h = 4h; + assert ( h == hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + minutes min = 36min; + assert ( min == minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + seconds s = 24s; + assert ( s == seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + milliseconds ms = 247ms; + assert ( ms == milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + microseconds us = 867us; + assert ( us == microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + nanoseconds ns = 645ns; + assert ( ns == nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/test/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp b/test/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp new file mode 100644 index 00000000..17358e58 --- /dev/null +++ b/test/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp @@ -0,0 +1,22 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::chrono::hours; + + hours foo = 4h; // should fail w/conversion operator not found +#else +#error +#endif +} diff --git a/test/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp b/test/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp new file mode 100644 index 00000000..e37bc6e6 --- /dev/null +++ b/test/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include +#include +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals; + + std::chrono::hours h = 4h; + assert ( h == std::chrono::hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + std::chrono::minutes min = 36min; + assert ( min == std::chrono::minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + std::chrono::seconds s = 24s; + assert ( s == std::chrono::seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + std::chrono::milliseconds ms = 247ms; + assert ( ms == std::chrono::milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + std::chrono::microseconds us = 867us; + assert ( us == std::chrono::microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + std::chrono::nanoseconds ns = 645ns; + assert ( ns == std::chrono::nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +}