“类型不完整”(但不是)并且代码编译

Tim*_*imo 5 c++ intellisense template-specialization visual-studio-2015

我有一个模板课

template<typename EventT, typename StateT, typename ActionT, bool InjectEvent = false, bool InjectStates = false, bool InjectMachine = false>
class StateMachine;
Run Code Online (Sandbox Code Playgroud)

和它的专业化

template<typename EventT, typename StateT, typename ActionResultT, typename ...ActionArgsT, bool InjectEvent, bool InjectStates, bool InjectMachine>
class StateMachine<EventT, StateT, ActionResultT(ActionArgsT...), InjectEvent, InjectStates, InjectMachine>
Run Code Online (Sandbox Code Playgroud)

专业化用于将函数类型解析为其返回值和参数类型。

该类的实现按预期工作,并通过了所有测试。

如果我默认值添加到ActionT通过使ActionT = void(),Visual Studio中抱怨“式的StateMachine <...>是不完整的”智能感知和停止工作(至少对于这种类型的所有实例)。但是,代码会像以前一样通过编译并通过所有测试(我还有一个测试明确使用默认参数)。

这是Visual Studio中的错误,还是我错过了什么?

我正在使用VS 2015 Pro和C ++ 14。

编辑

这是一个最小的工作示例:

#include <iostream>
#include <functional>

using namespace std;

template<typename EventT, typename StateT, typename ActionT = void(), bool InjectEvent = false, bool InjectStates = false, bool InjectMachine = false>
class StateMachine;

template<typename EventT, typename StateT, typename ActionResultT, typename ...ActionArgsT, bool InjectEvent, bool InjectStates, bool InjectMachine>
class StateMachine<EventT, StateT, ActionResultT(ActionArgsT...), InjectEvent, InjectStates, InjectMachine>
{
public:
    typedef ActionResultT ActionT(ActionArgsT...);

    StateMachine(ActionT&& action) : _action(action)
    {        
    }

    ActionResultT operator()(ActionArgsT... args)
    {
        return _action(args...);
    }

    void sayHello() const
    {
        cout << "hello" << endl;
    }

private:
    function<ActionT> _action;
};

int sum(int a, int b)
{
    return a + b;
}

void print()
{
    cout << "hello world" << endl;
}

void main()
{
    StateMachine<string, int, int(int, int)> sm1(sum);
    sm1.sayHello();
    cout << sm1(2, 5) << endl;
    StateMachine<string, int> sm2(print);
    sm2();
    sm2.sayHello();
    getchar();
}
Run Code Online (Sandbox Code Playgroud)

IntelliSense引发此错误:

对于sm1,它找到成员函数sayHello()...

但不适用于sm2

但是,代码编译并产生以下输出:

hello
7
hello world
hello
Run Code Online (Sandbox Code Playgroud)

哪个是正确的。

Tim*_*imo 3

我终于弄清楚这是Resharper的intellisense的问题。如果我禁用 Resharper,代码将不再带有下划线。我会将此事报告给 JetBrains 并让您了解最新情况。

编辑

万恶之源是将函数类型替换为函数签名:

template<typename FT = void()>
struct Func;

template<typename FR, typename ...FArgs>
struct Func<FR(FArgs...)>
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

更新

我在youtrack (JetBrain 的问题跟踪器)上开了一张票,并已为其分配了一名开发人员。