"Cannot convert initializer list to return type 'std::set<MyEnum>'" reported for more than 2 entries

Please take a look at this smallest repro that I have:

 

enum MyEnum
{
MY_ENTRY_1,
MY_ENTRY_2,
MY_ENTRY_3
};

std::set<MyEnum> MyFunction()
{
return
{
MY_ENTRY_1,
MY_ENTRY_2,
MY_ENTRY_3
};
}

 

ReSharper C++ underscores in red all 3 returned entries plus the brackets and reports the error as in the title.

If I reduce the number of returned entries to two the error goes away. Is there something wrong with the example or is it false detection?

 

Thanks,

Kamil

0
8 comments
Avatar
Permanently deleted user

Hello Kamil,

I can't seem to reproduce this issue. Which Visual Studio, MSVC toolset and ReSharper version are you using?

Thanks,

Igor

0
Avatar
Permanently deleted user

It repros for me in:

Microsoft Visual Studio Professional 2012
Version 11.0.60610.01 Update 3
Microsoft .NET Framework
Version 4.6.01055

 

Interestingly (just checked) this example _doesn't_ repro on the same system with:

Microsoft Visual Studio Professional 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01055

 

In both cases it is freshly installed ReSharper:

JetBrains ReSharper Ultimate 2016.2.2 Build 106.0.20160913.91321
ReSharper C++ 2016.2.20160913.92511

 

Thanks,

Kamil 

 

0
Avatar
Permanently deleted user

But this example does not compile on VS2012, does it?

VS2012 lacks uniform initialization. R++'s parser does not check at the moment whether the current toolset has uniform initialization. With three arguments R++ looks for a constructor which accepts std::initializer_list, does not find one and complains. With two arguments the "template<class _Iter> set(_Iter _First, _Iter _Last)" constructor can be used for uniform initialization (you can navigate to the constructor from the opening curly brace), so everything is alright.

0
Avatar
Permanently deleted user

I haven't checked if it compiles with msvc 2012...

This might be a situation you have not considered:

I am using "Makefile" type of project in VS2012, but the source is compiled with 2015 "cl", so the build is fine. I am just using 2012 IDE even though the compiler is newer.

Looks like ReSharper somehow assumes the cl is from 2012. How does it do that? Can this be switched?

 

Thanks,

Kamil

0
Avatar
Permanently deleted user

So it looks like ReSharper uses standard library headers from VS2012? Could you confirm this by navigating to some standard header and checking its location?

For Makefile projects ReSharper concatenates include paths from "VC++ Directories | Include Directories" and "NMake | IntelliSense | Include Search Path". If you compile with VS2015 toolset, shouldn't "VC++ Directories | Include Directories" be set to point at VS2015 headers? I believe nmake uses these paths during compilation.

0
Avatar
Permanently deleted user

I have put the standard 2015 headers path into IntelliSense | Include Search Path box.

I didn't think about what is in VC++ Directories since before installing ReSharper they were unused anyway.

I now have cleaned everything in "VC++ Directories" and also put the really used "msvc140\VC\include" path in VC++ Directories | Include Directories. None of that has helped with the error.

0
Avatar
Permanently deleted user

Could you please clear caches (ReSharper | Options | Environment | General | Clear Caches) and reopen the solution? If you navigate to <set>, which file does R++ open? If this does not help, could you please show your vcxproj file? (Either send it to igor.akhmetov@jetbrains.com or create an RSCPP issue at https://youtrack.jetbrains.com and attach the project file to it).

0
Avatar
Permanently deleted user

The clear caches procedure has solved it.

 

To summarize the root cause was leaving VC++ Directories at their default values pointing to 2012 headers.

 

Thanks a lot for all the help!

Best regards,

Kamil

0

Please sign in to leave a comment.