This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/67348] New: [concepts] Constraints, special member functions, and default/delete
- From: "Casey at Carter dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 25 Aug 2015 04:18:54 +0000
- Subject: [Bug c++/67348] New: [concepts] Constraints, special member functions, and default/delete
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67348
Bug ID: 67348
Summary: [concepts] Constraints, special member functions, and
default/delete
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Casey at Carter dot net
Target Milestone: ---
Having recently implemented N4542's variant, it would be very convenient to be
able to write e.g.:
template <class...Ts>
requires (is_destructible<Ts>::value && ...)
struct variant {
~variant() { /* ... */ }
~variant()
requires (is_trivially_destructible<Ts>::value && ...) = default;
variant(variant&&) { /* ... */ }
variant(variant&&)
requires (is_trivially_move_constructible<Ts>::value && ...) = default;
variant& operator=(variant&&) { /* ... */ }
variant& operator=(variant&&)
requires (is_trivially_move_assignable<Ts>::value && ...) = default;
// ...similar treatment for copy construction / assignment...
};
static_assert(std::is_trivially_destructible<variant<int, float>>());
static_assert(!std::is_trivially_destructible<variant<int, vector<int>>>());
static_assert(std::is_trivially_move_constructible<variant<int, float>>());
static_assert(!std::is_trivially_move_constructible<variant<int,
vector<int>>>());
Formally, constraints are forbidden for destructors and non-template
constructors since the Concepts TS does not change the required syntax forms in
[class.ctor]/1 and [class.dtor]/1 to allow for an optional requires-clause;
this is likely an oversight. GCC currently allows a requires-clause on
constructor and destructor declarations, but breaks badly when multiple
destructors are overloaded or when constraints are used in conjunction with
default/delete.
I suppose this is therefore both a bug report - compiler fails to diagnose as
ill-formed code which truly should be well-formed ;) - and a feature request
for both the compiler and the Concepts TS. I would be happy to provide
specification wording for constraints on special member functions and semantic
interaction with default/delete if I could interest anyone in implementing the
behavior in the compiler as an extension.