Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should MSVC's C4138 warning ("'*/' found outside of comment") be disabled?

Tags:

c++

visual-c++

When compiling the following code with msvc2017

void Foo::bar(A */*a*/)

I get this warning:

foo.cpp:38: warning: C4138: '*/' found outside of comment

I can fix this by adding a space after the asterisk:

void Foo::bar(A * /*a*/)

however, I would have to do this in a bunch of places, and if I ever uncomment the parameter, the coding style I use won't be followed due to the extra space.

Since I don't get the same warning with gcc or clang, I'm wondering if this is a MSVC-specific quirk that can safely be disabled.

like image 285
Mitch Avatar asked Oct 27 '22 19:10

Mitch


1 Answers

Yes this is a unwarranted warning; there is nothing wrong with the code you present. In fact, commenting out variable names in function definitions can be useful for example when you want to suppress "unused variable" warnings in function parameters lists that are self-documenting.

  1. Switch off the warning and rely on the compiler to issue a diagnostic if indeed there is a mismatched comment block in your code.

  2. Submit a bug report to the compiler vendor.

like image 65
Bathsheba Avatar answered Nov 15 '22 08:11

Bathsheba