3

Is there a patch out there (official or unofficial) to get IntelliSense to stop reporting every use of decltype as a syntax error? It compiles fine, so I know decltype is supported, but it's very distracting seeing red squiggles everywhere and makes it much harder to find actual errors in the code. Every compile gives me a list of hundreds of non-errors - basically at least 3 for every use of decltype in the code base, e.g.:

std::for_each(std::begin(list), std::end(list), [](const decltype(list)::value_type& item)
{
    <do stuff with item>
});

will produce the following (non) errors:

IntelliSense: global-scope qualifier (leading '::') is not allowed
IntelliSense: expected a ')'
IntelliSense: identifier "item" is undefined

Upgrading to VS2015 is not an option at this point. (I doubt I could convince the company to shell out to upgrade every computer, and upgrading only some of them would lead to backwards compatibility issues.)

Personally, I'd prefer not to use decltype at all until we get an IDE that fully supports it (there's nowhere I know of that you actually need it), but I don't think I can convince everybody of that either. I just want to make all those fake errors go away so that I can find the real ones without poring over thousands of false-positives.

Darrel Hoffman
  • 4,436
  • 6
  • 29
  • 41
  • u now, upgrade to vs 2015, like? free! – Cheers and hth. - Alf Mar 15 '16 at 15:14
  • 1
    Your best bet may be the 2015 community edition with the V120 toolset to retain Visual Studio 2013 compatibility. I have not tested this however. – drescherjm Mar 15 '16 at 15:17
  • @Cheersandhth.-Alf - Is it? Still, free or not, there's no way the company is going to upgrade all the systems in mid-project. Certainly not at my request. Too much chance for chaos. – Darrel Hoffman Mar 15 '16 at 15:18
  • 2
    The community edition is not always free of charge for commercial use, and this question is about use in a company. See [MICROSOFT SOFTWARE LICENSE TERMS](https://www.visualstudio.com/support/legal/mt171547) for details. The comments here should be ignored, they're useless. Unless they're attempting to encourage unauthorised use, in which case they're worse than useless. –  Mar 15 '16 at 15:29
  • @hvd: Thank you. I did state that upgrading was not an option for a reason. If this were my home computer, I would do just that, but I was hoping for some way to fix this without an upgrade. Surprised that with all of the 3rd party plug-ins out there, there doesn't seem to be one to fix this obvious oversight. – Darrel Hoffman Mar 15 '16 at 15:36

1 Answers1

3

Given a helper template alias

template <typename T> using id = T;

you can avoid the Intellisense errors, while still keeping the code perfectly valid, by writing id<decltype(list)>::value_type where you would otherwise have written decltype(list)::value_type.

Depending on how often decltype is immediately followed by ::, you may want to create a macro as simple as:

#define DECLTYPE(x) id<decltype(x)>
  • This does work. Unfortunately, it would require hundreds of (admittedly minor) changes to the code in order to fully implement, and I'd have to get that kind of thing cleared with a lot of people. I might bring it up at the next code review. It's worth a +1, but I'm still hoping for a solution that doesn't require changing all of the code. – Darrel Hoffman Mar 15 '16 at 16:54
  • You *could* name your macro `decltype` and put it in a common header, I suppose... but I'm not so sure that's a good idea. –  Mar 15 '16 at 18:02
  • @hvd: It wouldn't be so bad if done within a `#ifdef __INTELLISENSE__` guard. – MSalters Mar 16 '16 at 12:57