aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Voutilainen <ville.voutilainen@gmail.com>2015-11-11 16:47:19 +0200
committerVille Voutilainen <ville@gcc.gnu.org>2015-11-11 16:47:19 +0200
commit269fa2a91b6d96ca71776077082f2538d6e032cb (patch)
treea2e12c097060dfba72c4948b13a0f5d486705daa
parente78bede6f774bc0d294adafe5e3367c4da10647e (diff)
downloadgcc-269fa2a91b6d96ca71776077082f2538d6e032cb.zip
gcc-269fa2a91b6d96ca71776077082f2538d6e032cb.tar.gz
gcc-269fa2a91b6d96ca71776077082f2538d6e032cb.tar.bz2
LWG 2510, make the default constructors of library tag types explicit.
2015-11-10 Ville Voutilainen <ville.voutilainen@gmail.com> LWG 2510, make the default constructors of library tag types explicit. * include/bits/mutex.h (defer_lock_t, try_lock_t, adopt_lock_t): Add an explicit default constructor. * include/bits/stl_pair.h (piecewise_construct_t): Likewise. * include/bits/uses_allocator.h (allocator_arg_t): Likewise. * libsupc++/new (nothrow_t): Likewise. * testsuite/17_intro/tag_type_explicit_ctor.cc: New. From-SVN: r230175
-rw-r--r--libstdc++-v3/ChangeLog11
-rw-r--r--libstdc++-v3/include/bits/mutex.h6
-rw-r--r--libstdc++-v3/include/bits/stl_pair.h2
-rw-r--r--libstdc++-v3/include/bits/uses_allocator.h2
-rw-r--r--libstdc++-v3/libsupc++/new7
-rw-r--r--libstdc++-v3/testsuite/17_intro/tag_type_explicit_ctor.cc60
6 files changed, 82 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 960a56c..ebe7755 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,14 @@
+2015-11-10 Ville Voutilainen <ville.voutilainen@gmail.com>
+
+ LWG 2510, make the default constructors of library tag types
+ explicit.
+ * include/bits/mutex.h (defer_lock_t, try_lock_t,
+ adopt_lock_t): Add an explicit default constructor.
+ * include/bits/stl_pair.h (piecewise_construct_t): Likewise.
+ * include/bits/uses_allocator.h (allocator_arg_t): Likewise.
+ * libsupc++/new (nothrow_t): Likewise.
+ * testsuite/17_intro/tag_type_explicit_ctor.cc: New.
+
2015-11-11 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/64651
diff --git a/libstdc++-v3/include/bits/mutex.h b/libstdc++-v3/include/bits/mutex.h
index 43f5b0b..dd27989 100644
--- a/libstdc++-v3/include/bits/mutex.h
+++ b/libstdc++-v3/include/bits/mutex.h
@@ -129,14 +129,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif // _GLIBCXX_HAS_GTHREADS
/// Do not acquire ownership of the mutex.
- struct defer_lock_t { };
+ struct defer_lock_t { explicit defer_lock_t() = default; };
/// Try to acquire ownership of the mutex without blocking.
- struct try_to_lock_t { };
+ struct try_to_lock_t { explicit try_to_lock_t() = default; };
/// Assume the calling thread has already obtained mutex ownership
/// and manage it.
- struct adopt_lock_t { };
+ struct adopt_lock_t { explicit adopt_lock_t() = default; };
constexpr defer_lock_t defer_lock { };
constexpr try_to_lock_t try_to_lock { };
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index dfcd357..d6f6b86 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -73,7 +73,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
/// piecewise_construct_t
- struct piecewise_construct_t { };
+ struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
/// piecewise_construct
constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h
index f9ea7d6..a0f084d 100644
--- a/libstdc++-v3/include/bits/uses_allocator.h
+++ b/libstdc++-v3/include/bits/uses_allocator.h
@@ -36,7 +36,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/// [allocator.tag]
- struct allocator_arg_t { };
+ struct allocator_arg_t { explicit allocator_arg_t() = default; };
constexpr allocator_arg_t allocator_arg = allocator_arg_t();
diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new
index 0f6a05a..8621f73 100644
--- a/libstdc++-v3/libsupc++/new
+++ b/libstdc++-v3/libsupc++/new
@@ -79,7 +79,12 @@ namespace std
};
#endif
- struct nothrow_t { };
+ struct nothrow_t
+ {
+#if __cplusplus >= 201103L
+ explicit nothrow_t() = default;
+#endif
+ };
extern const nothrow_t nothrow;
diff --git a/libstdc++-v3/testsuite/17_intro/tag_type_explicit_ctor.cc b/libstdc++-v3/testsuite/17_intro/tag_type_explicit_ctor.cc
new file mode 100644
index 0000000..4b9d217
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/tag_type_explicit_ctor.cc
@@ -0,0 +1,60 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2015 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <new>
+#include <utility>
+#include <memory>
+#include <mutex>
+
+void f1(std::nothrow_t);
+void f2(std::piecewise_construct_t);
+void f3(std::allocator_arg_t);
+void f4(std::defer_lock_t);
+void f5(std::try_to_lock_t);
+void f6(std::adopt_lock_t);
+
+
+int main()
+{
+ std::nothrow_t v1;
+ std::piecewise_construct_t v2;
+ std::allocator_arg_t v3;
+ std::defer_lock_t v4;
+ std::try_to_lock_t v5;
+ std::try_to_lock_t v6;
+ std::nothrow_t v7 = {}; // { dg-error "explicit" }
+ std::piecewise_construct_t v8 = {}; // { dg-error "explicit" }
+ std::allocator_arg_t v9 = {}; // { dg-error "explicit" }
+ std::defer_lock_t v10 = {}; // { dg-error "explicit" }
+ std::try_to_lock_t v11 = {}; // { dg-error "explicit" }
+ std::try_to_lock_t v12 = {}; // { dg-error "explicit" }
+ f1(std::nothrow_t{});
+ f2(std::piecewise_construct_t{});
+ f3(std::allocator_arg_t{});
+ f4(std::defer_lock_t{});
+ f5(std::try_to_lock_t{});
+ f6(std::adopt_lock_t{});
+ f1({}); // { dg-error "explicit" }
+ f2({}); // { dg-error "explicit" }
+ f3({}); // { dg-error "explicit" }
+ f4({}); // { dg-error "explicit" }
+ f5({}); // { dg-error "explicit" }
+ f6({}); // { dg-error "explicit" }
+}