6

I have a template class

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

and a specialization of it

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

The specialization is used to resolve the function type to its return- and parameter types.

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

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

Is this a bug in Visual Studio or do I miss something?

I'm 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 throws this error:

For sm1 it finds the member function sayHello()...

but not for sm2

However the code compiles and produces this output:

hello
7
hello world
hello

which is correct.

Timo
  • 9,269
  • 2
  • 28
  • 58
  • 1
    Please provide a [mcve]. – Barry Feb 14 '17 at 20:53
  • I don't know if this helps you, but your code works fine on `g++` and `clang++` – tforgione Feb 15 '17 at 09:30
  • It also works on msvc. I think this is a problem with the IntelliSense parser. – Timo Feb 15 '17 at 09:34
  • Does this intellisense issue only happens for this project? You can have a try with those troubleshot methods: 1: Close VS and Unload, then reload the solution, 2: Right click the solution name and select ‘Clean Solution’ 3: Close VS and delete the .suo file or the .csproj.user file of your current solution (please backup it firstly) and reopen this solution again. – Sara Liu - MSFT Feb 15 '17 at 10:13
  • No this happens at multiple projects. The code above comes from a clean solution that just contains that code. I've also tried unloading the projects, deleting the .suo file and cleaning the project. Unfortunately, none of it solved my problem. – Timo Feb 15 '17 at 10:20
  • Please go to Control Panel--Programs and Features and right click the VS professional 2015, Change-Repair. After that, check this issue again. Now the latest version of VS 2015 professional is VS professional 2015 with update 3, you can go to Help-About Microsoft Visual Studio and check if the update is installed or not. If not, go to Tools-Extensions and Updates, click 'Updates' tab, there should lists the Visual Studio 2015 Update 3 and download it to install. – Sara Liu - MSFT Feb 16 '17 at 07:31
  • Already tried it, didn't help. This is a clean reinstall of VS that I installed a week ago, so updates aren't a problem either. – Timo Feb 16 '17 at 08:29
  • Try to copy your whole solution to your colleague or friend computer who have the same VS version as yours, if the intellisense issue display, this issue is more relates to your VS. You can try to reset the setting of VS, go to Tools- Import and Export Settings… and select ‘Reset all settings’, then save your current settings, then click ‘Finish’ button to reset the customized setting to the default, it can help us to excludes the customized setting caused this issue. If this issue persists on other computers, it seems this issue is more relates to your projects. – Sara Liu - MSFT Feb 17 '17 at 02:30
  • @Sara-MSFT I will give it a try later. Can anybody confirm this error or is it just me? I read in another topic here (unfortunately, I can't find it anymore) that intellisense's syntax parser is different to the the compiler's parser. Maybe this is one of the differences? – Timo Feb 17 '17 at 08:21

1 Answers1

3

I finally figured out that this is a problem of Resharper's intellisense. If I disable Resharper the code is not underlined anymore. I will report this to JetBrains and keep you up to date.

Edit

The root of all evil is the substitution of the function type into the function signature:

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

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

Update

I opened a ticket on youtrack (JetBrain's issue tracker) and a developer has been assigned to it.

Timo
  • 9,269
  • 2
  • 28
  • 58