c++templatesc++17template-argument-deduction

Error C2988 (unrecognizable template declaration/definition) deducing method return type


I'm getting error C2988 (unrecognizable template declaration/definition), the cursor hinting immediately before the *method parameter.

namespace Bind 
{
    template <typename ModelClass, typename ReturnType>
    static std::unique_ptr<Binding> 
    Get (ReturnType (ModelClass::*method)(),
         const String& source,
         const Symbol& aspect = {})
    {
    // whatever
    return nullptr;
    }

    // ....
}

Example instantiation: Function WhateverClass::whateverMemberFunction() returns ReturnType and takes no arguments. Both template arguments ModelClass and ReturnType are supposed to be deduced from this instantiation:

Bind::Get(&WhateverClass::whateverMemberFunction, "")

The template compiles fine with Xcode (Apple) but fails with MSVC 2019. Both are using C++17 standard.

What am I missing?


Solution

  • This is definitely a msvc bug. MSVC seems to be having problem with using {} as default when one of the parameter is of member pointer type.

    Workaround

    You can change {} to Symbol{} as shown below:

    Get (ReturnType (ModelClass::*method)(), const String& source,
    //---------------------vvvvvv---->changed to this    
    const Symbol& aspect = Symbol{})
    {
     }
    

    Here is the newly submitted msvc bug:

    MSVC rejects valid program with {} as default argument when a parameter is of member pointer type