Enable visual studio c++ syntax error warnings when using template

I'm using visual studio 2017 and I noticed that I don't get syntax error warnings when using template, for example:

no warnings

and when I remove the template I get this: enter image description here

and this:

enter image description here

Is it possible to fix this?

code(not image):

template<int a>
void noErrors()
{
    sleiudbg;sg ojrp jabp srpghs //some gibberish
}
template<int b>
void noErrors(string s)
{
    int p = s.Size();
}

Upvotes: 2

Views: 709

Answers (1)

catnip
catnip

Reputation: 25408

Oh please, must we post code only as images? Please fix that, it means I cannot experiment with your code.

But the answer to your question is that the incremental syntax checker built into the IDE is of limited intelligence, especially where templates are concerned (where detecting and reporting compiler errors in general is a complex business) and as a result a great deal of stuff which is not going to compile slips through.

The compiler, on the other hand, will throw this out straightaway, and also report errors resulting from an invalid instantiation of a template in a moderately helpful way (although such error messages are never the easiest things to read).

And can you change any of this? Sorry, no, (unless you can persuade Microsoft to beef-up their IDE).


where error checking is a complex business - more here:

What does a compiler check for uninstantiated template code?

Upvotes: 1

Related Questions