[libcxx] r235134 - A few bits of N2994 didn't get fully implemented a long time ago. Thanks to STL at microsoft.com for the bug report
Marshall Clow
mclow.lists at gmail.com
Thu Apr 16 14:36:54 PDT 2015
Author: marshall
Date: Thu Apr 16 16:36:54 2015
New Revision: 235134
URL: http://llvm.org/viewvc/llvm-project?rev=235134&view=rev
Log:
A few bits of N2994 didn't get fully implemented a long time ago. Thanks to STL at microsoft.com for the bug report
Added:
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.fail.cpp
Modified:
libcxx/trunk/include/iterator
libcxx/trunk/include/ratio
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.pass.cpp
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/istreambuf.iterator.cons/default.pass.cpp
libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp
libcxx/trunk/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp
Modified: libcxx/trunk/include/iterator
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Thu Apr 16 16:36:54 2015
@@ -214,7 +214,7 @@ public:
typedef traits traits_type;
typedef basic_istream<charT,traits> istream_type;
- istream_iterator();
+ constexpr istream_iterator();
istream_iterator(istream_type& s);
istream_iterator(const istream_iterator& x);
~istream_iterator();
@@ -765,7 +765,7 @@ private:
istream_type* __in_stream_;
_Tp __value_;
public:
- _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
_LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
{
if (!(*__in_stream_ >> __value_))
Modified: libcxx/trunk/include/ratio
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ratio?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/include/ratio (original)
+++ libcxx/trunk/include/ratio Thu Apr 16 16:36:54 2015
@@ -21,8 +21,8 @@ template <intmax_t N, intmax_t D = 1>
class ratio
{
public:
- static const intmax_t num;
- static const intmax_t den;
+ static constexpr intmax_t num;
+ static constexpr intmax_t den;
typedef ratio<num, den> type;
};
@@ -236,13 +236,13 @@ class _LIBCPP_TYPE_VIS_ONLY ratio
static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range");
static_assert(_Den != 0, "ratio divide by 0");
static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range");
- static const intmax_t __na = __static_abs<_Num>::value;
- static const intmax_t __da = __static_abs<_Den>::value;
- static const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value;
- static const intmax_t __gcd = __static_gcd<__na, __da>::value;
+ static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>::value;
+ static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>::value;
+ static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value;
+ static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>::value;
public:
- static const intmax_t num = __s * __na / __gcd;
- static const intmax_t den = __da / __gcd;
+ static _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd;
+ static _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd;
typedef ratio<num, den> type;
};
Added: libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.fail.cpp?rev=235134&view=auto
==============================================================================
--- libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.fail.cpp (added)
+++ libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.fail.cpp Thu Apr 16 16:36:54 2015
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <iterator>
+
+// class istream_iterator
+
+// constexpr istream_iterator();
+
+#include <iterator>
+#include <cassert>
+
+struct S { S(); }; // not constexpr
+
+int main()
+{
+#if __cplusplus >= 201103L
+ {
+ constexpr std::istream_iterator<S> it;
+ }
+#else
+#error "C++11 only test"
+#endif
+}
Modified: libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.pass.cpp?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.pass.cpp (original)
+++ libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.cons/default.pass.cpp Thu Apr 16 16:36:54 2015
@@ -11,13 +11,20 @@
// class istream_iterator
-// istream_iterator();
+// constexpr istream_iterator();
#include <iterator>
#include <cassert>
int main()
{
- std::istream_iterator<int> i;
- assert(i == std::istream_iterator<int>());
+ {
+ typedef std::istream_iterator<int> T;
+ T it;
+ assert(it == T());
+#if __cplusplus >= 201103L
+ constexpr T it2;
+#endif
+ }
+
}
Modified: libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp (original)
+++ libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp Thu Apr 16 16:36:54 2015
@@ -19,9 +19,14 @@
// typedef traits traits_type;
// typedef basic_istream<charT,traits> istream_type;
// ...
+//
+// If T is a literal type, then the default constructor shall be a constexpr constructor.
+// If T is a literal type, then this constructor shall be a trivial copy constructor.
+// If T is a literal type, then this destructor shall be a trivial destructor.
#include <iterator>
#include <type_traits>
+#include <string>
int main()
{
@@ -32,6 +37,9 @@ int main()
static_assert((std::is_same<I1::char_type, char>::value), "");
static_assert((std::is_same<I1::traits_type, std::char_traits<char> >::value), "");
static_assert((std::is_same<I1::istream_type, std::istream>::value), "");
+ static_assert( std::is_trivially_copy_constructible<I1>::value, "");
+ static_assert( std::is_trivially_destructible<I1>::value, "");
+
typedef std::istream_iterator<unsigned, wchar_t> I2;
static_assert((std::is_convertible<I2,
std::iterator<std::input_iterator_tag, unsigned, std::ptrdiff_t,
@@ -39,4 +47,10 @@ int main()
static_assert((std::is_same<I2::char_type, wchar_t>::value), "");
static_assert((std::is_same<I2::traits_type, std::char_traits<wchar_t> >::value), "");
static_assert((std::is_same<I2::istream_type, std::wistream>::value), "");
+ static_assert( std::is_trivially_copy_constructible<I2>::value, "");
+ static_assert( std::is_trivially_destructible<I2>::value, "");
+
+ typedef std::istream_iterator<std::string> I3;
+ static_assert(!std::is_trivially_copy_constructible<I3>::value, "");
+ static_assert(!std::is_trivially_destructible<I3>::value, "");
}
Modified: libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/istreambuf.iterator.cons/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/istreambuf.iterator.cons/default.pass.cpp?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/istreambuf.iterator.cons/default.pass.cpp (original)
+++ libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/istreambuf.iterator.cons/default.pass.cpp Thu Apr 16 16:36:54 2015
@@ -10,8 +10,11 @@
// <iterator>
// istreambuf_iterator
-
+//
// istreambuf_iterator() throw();
+//
+// All specializations of istreambuf_iterator shall have a trivial copy constructor,
+// a constexpr default constructor and a trivial destructor.
#include <iterator>
#include <sstream>
@@ -20,11 +23,19 @@
int main()
{
{
- std::istreambuf_iterator<char> i;
- assert(i == std::istreambuf_iterator<char>());
+ typedef std::istreambuf_iterator<char> T;
+ T it;
+ assert(it == T());
+#if __cplusplus >= 201103L
+ constexpr T it2;
+#endif
}
{
- std::istreambuf_iterator<wchar_t> i;
- assert(i == std::istreambuf_iterator<wchar_t>());
+ typedef std::istreambuf_iterator<wchar_t> T;
+ T it;
+ assert(it == T());
+#if __cplusplus >= 201103L
+ constexpr T it2;
+#endif
}
}
Modified: libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp (original)
+++ libcxx/trunk/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp Thu Apr 16 16:36:54 2015
@@ -22,6 +22,9 @@
// typedef basic_streambuf<charT,traits> streambuf_type;
// typedef basic_istream<charT,traits> istream_type;
// ...
+//
+// All specializations of istreambuf_iterator shall have a trivial copy constructor,
+// a constexpr default constructor and a trivial destructor.
#include <iterator>
#include <string>
@@ -38,6 +41,9 @@ int main()
static_assert((std::is_same<I1::int_type, I1::traits_type::int_type>::value), "");
static_assert((std::is_same<I1::streambuf_type, std::streambuf>::value), "");
static_assert((std::is_same<I1::istream_type, std::istream>::value), "");
+ static_assert((std::is_nothrow_default_constructible<I1>::value), "" );
+ static_assert((std::is_trivially_copy_constructible<I1>::value), "" );
+ static_assert((std::is_trivially_destructible<I1>::value), "" );
typedef std::istreambuf_iterator<wchar_t> I2;
static_assert((std::is_convertible<I2,
@@ -48,4 +54,7 @@ int main()
static_assert((std::is_same<I2::int_type, I2::traits_type::int_type>::value), "");
static_assert((std::is_same<I2::streambuf_type, std::wstreambuf>::value), "");
static_assert((std::is_same<I2::istream_type, std::wistream>::value), "");
+ static_assert((std::is_nothrow_default_constructible<I2>::value), "" );
+ static_assert((std::is_trivially_copy_constructible<I2>::value), "" );
+ static_assert((std::is_trivially_destructible<I2>::value), "" );
}
Modified: libcxx/trunk/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp?rev=235134&r1=235133&r2=235134&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp Thu Apr 16 16:36:54 2015
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-// test ratio: The static data members num and den shall have thcommon
+// test ratio: The static data members num and den shall have the common
// divisor of the absolute values of N and D:
#include <ratio>
More information about the cfe-commits
mailing list