This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[patch] libstdc++/13860 enforce requirements on traits
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 8 May 2014 19:30:49 +0100
- Subject: [patch] libstdc++/13860 enforce requirements on traits
- Authentication-results: sourceware.org; auth=none
Add static assertions to enforce requirements on the traits used with
basic_filebuf, improving the diagnostics for invalid traits.
Tested x86_64-linux, committed to trunk.
commit 78df7e78e805c873883e63d9df4e6befa32ddac5
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu May 8 18:20:37 2014 +0100
PR libstdc++/13860
* include/std/fstream (basic_filebuf): Enforce requirements on traits.
diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream
index 17ccac6..51db21b 100644
--- a/libstdc++-v3/include/std/fstream
+++ b/libstdc++-v3/include/std/fstream
@@ -71,6 +71,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
{
+#if __cplusplus >= 201103L
+ template<typename _Tp>
+ using __chk_state = __and_<is_copy_assignable<_Tp>,
+ is_copy_constructible<_Tp>,
+ is_default_constructible<_Tp>>;
+
+ static_assert(__chk_state<typename _Traits::state_type>::value,
+ "state_type must be CopyAssignable, CopyConstructible"
+ " and DefaultConstructible");
+
+ static_assert(is_same<typename _Traits::pos_type,
+ fpos<typename _Traits::state_type>>::value,
+ "pos_type must be fpos<state_type>");
+#endif
public:
// Types:
typedef _CharT char_type;