C++ Logo


Advanced search

Trailing requires-clauses on destructors

From: Myria <myriachan_at_[hidden]>
Date: Tue, 26 Nov 2019 20:26:43 -0800
Is it well-formed to have requires-clauses on destructors? Here is an example:

void Display(int);
template <typename T> struct Meow {
    ~Meow() requires (std::is_trivially_destructible_v<T>) {
    ~Meow() requires (!std::is_trivially_destructible_v<T>) {
    T x;

Additionally, is this variant legal? (This was the point of this code
originally, to try to make a destructor trivial whenever the type is
trivially destructible.)

    ~Meow() requires (std::is_trivially_destructible_v<T>) = default;

This has implementation divergence on the Godbolt compilers and newest
MSVC 2019.

GCC 10: Both are allowed.

MSVC 19.23: First is allowed. Second gives an error: "multiple
versions of a defaulted special member functions are not allowed".

Clang with experimental concepts: Both give the same error: when using
a non-trivially destructible type T, invalid reference to ~Meow
because the requires expression is false and Clang is only checking
the first destructor.


Received on 2019-11-26 22:29:16