vendredi 31 juillet 2015

cv-qualified struct's member is not similarly cv-qualified

According to this answer, the following code should be compiled without error:

#include <type_traits>

namespace
{

struct A { int i; };

volatile A a{};
static_assert(std::is_volatile< decltype(a) >{});
static_assert(std::is_volatile< decltype(a.i) >{});

}

but there is a hard error:

main.cpp:10:1: error: static_assert failed
static_assert(std::is_volatile< decltype(a.i) >{});
^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Live example with clang 3.6.0.

Is it a clang bug or am I missing something substantial?

ADDITIONAL:

#include <type_traits>

namespace
{

struct A { int i; };

const A a{};
static_assert(std::is_const< decltype(a) >{});
static_assert(std::is_const< decltype(a.i) >{});

}

Exactly the same behaviour for the latter code snippet.

ADDITIONAL:

static_assert(std::is_volatile< std::remove_pointer_t< decltype(&a.i) > >{});

not cause an error.

Aucun commentaire:

Enregistrer un commentaire