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>&.

posted on 2011-03-22 17:57 Enki 阅读(271) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜