I'm experiencing (what appears to me as) strange behaviour from Visual Studio when trying to check whether one class is derived from another. Consider the following samples:
Sample 1
namespace X
{
namespace Y
{
struct A {};
struct B {};
}
}
struct AB : public X::Y::A, public X::Y::B {};
static_assert(std::is_base_of_v<X::Y::A, AB>); // (1)
static_assert(std::is_base_of_v<X::Y::B, AB>); // (2)
Sample 2
namespace X
{
namespace Y
{
struct A {};
struct B {};
}
}
using namespace X::Y;
struct AB : public A, public B {};
static_assert(std::is_base_of_v<A, AB>); // (3)
static_assert(std::is_base_of_v<B, AB>); // (4)
I've added the /std:c++latest
option in Visual Studio, so to my understanding, nested namespaces should be fine.
If I set the Conformance Mode in Visual Studio to No, then all the static_assert
expressions above are satisfied.
However, if I set it to Yes (i.e. /permissive-
), then (3) is satisfied but all of (1), (2), and (4) fail. I'd appreciate any insight anyone can give into why this should be the case - is it my understanding at fault, or is it a VS issue? In particular, the fact that (3) and (4) can (and do!) differ is very odd.
IntelliSense wrongly marks them as failed but if you try to build the project it will compile successfully.
Intellisense is not a full featured compiler, it may not be as accurate or may not be updated to support the latest language features and sometimes disagrees with the compiler.