lundi 30 novembre 2015

Using new (nullptr) in decltype context

Is it allowed by the Standard to write decltype(::new (nullptr) T(std::declval< Args >()...)) or noexcept(::new (nullptr) T(std::declval< Args >()...))? Particularly interested placement new on nullptr correctness. Considering following code:

#include <type_traits>
#include <utility>

struct S { S(int) { ; } ~S() = delete; };

struct A
{
    template< typename T,
              bool is_noexcept = noexcept(::new (nullptr) S(std::declval< T >())) >
    A(T && x) noexcept(is_noexcept)
        : s(new S(std::forward< T >(x)))
    { ; }

    S * s;
};

static_assert(std::is_constructible< A, int >{});
static_assert(!std::is_constructible< A, void * >{});

Disabler typename = decltype(S(std::declval< T >())) would need presence of destructor, but placement new not.

Nevertheless unevaluated context of decltype and operator noexcept I wondering about conformance to the Standard. Because compiler may prove 100% incorectness of the tested expression.

Aucun commentaire:

Enregistrer un commentaire