unexpected value from is_base_of

unexpected value from is_base_of

C:\Temp>type meow.cpp

#include <type_traits>

 

template <typename T> struct A {

    A() {

        static_assert(std::is_base_of<A<T>, T>::value, "assert1");

        typedef typename std::remove_reference<decltype(*this)>::type meow_t;

        static_assert(std::is_base_of<meow_t, T>::value, "assert2");

    }

};

 

struct C : public A<C> { };

 

void foo() {

    C c;

}

 

C:\Temp>cl

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 17.00.40316 for 80x86

Copyright (C) Microsoft Corporation.  All rights reserved.

 

usage: cl [ option... ] filename... [ /link linkoption... ]

 

C:\Temp>cl /EHsc /nologo /W4 /c meow.cpp

meow.cpp

 

C:\Temp>

 

*this is an lvalue so decltype(*this) is indeed A<T>&.

你可能感兴趣的:(unexpected value from is_base_of)