"Type incomplete" (but not) and compiles the code

I have a template class

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

and his specialization

template<typename EventT, typename StateT, typename ActionResultT, typename ...ActionArgsT, bool InjectEvent, bool InjectStates, bool InjectMachine>
class StateMachine<EventT, StateT, ActionResultT(ActionArgsT...), InjectEvent, InjectStates, InjectMachine>

Specialization is used to resolve the type of a function to its return types and parameters.

The class implementation works as expected, and all tests are passed.

If I add a default value to ActionT, making it ActionT = void(), Visual Studio complains that "the StateMachine <...> type is incomplete", and IntelliSense stops working (at least for all instances of this type). However, the compilation of the code and all the tests are passed as before (I also have a test that explicitly uses the default argument).

Is this a bug in Visual Studio or am I missing something?

I am using VS 2015 Pro and C ++ 14.

EDIT

Here is a minimal working example:

#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();
}

IntelliSense :

sm1 - sayHello()...

sm2

:

hello
7
hello world
hello

.

+4
1

- , Resharper intellisense. Resharper, . JetBrains .

Edit

- :

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

template<typename FR, typename ...FArgs>
struct Func<FR(FArgs...)>
{
    // ...
}

youtrack ( JetBrain), .

+2

Source: https://habr.com/ru/post/1669729/


All Articles