C++ decltype fails to deduce type

前端 未结 2 1026
礼貌的吻别
礼貌的吻别 2021-01-19 14:20

Is decltype really buggy in Visual Studio 2012 or is it actually supposed to be this hard to use?

Example:

namespace ptl
{

    struct Test
    {
            


        
相关标签:
2条回答
  • 2021-01-19 14:44

    I agree with Dietmar: This is a bug in the compiler. The issue appears to be that decltype cannot be applied to an expression that takes the address of a function template specialization. That is, the following is a minimal repro for this issue:

    template <typename>
    void f();
    
    typedef decltype(&f<void>) t;
    

    As a workaround, consider applying decltype to the function template specialization directly, then adding * to form the required pointer type:

    inline auto ExampleFxn2()
        -> decltype(ptl::static_constructor<ptl::Test, float>)*
    {
       return &ptl::static_constructor<ptl::Test, float>;
    }
    

    Please consider opening a bug for this on Microsoft Connect and posting a link as a comment here for future readers (or, if you would prefer not to, let me know and I would be happy to open a bug for this issue).

    0 讨论(0)
  • 2021-01-19 14:46

    The type of &ptl::static_constructor<ptl::Test, float> can be deduced by decltype(). This looks like a bug in MSVC++. Both clang and gcc agree that the code is fine (assuming #include <new> is added).

    0 讨论(0)
提交回复
热议问题