When you compile a file with .cpp
extension, it is compiled as C++ code by default. In C++ language the requirement for function declarations is a mandatory, hard requirement. There's no point in making an -Wmissing-prototypes
option for C++.
In other words, you can't "turn on this warning" in C++ because "missing prototype" is always an error in C++.
P.S. As a side note: The notion of prototype is specific to C language only. There are no "prototypes" in C++.
In C language a function declaration can be a prototype or not a prototype, hence the need for an extra term to distinguish ones from the others. In C++ function declarations are always "prototypes" (from C point of view), so in C++ there simply no need for this extra term. In C++ function declarations are simply function declarations. That just says it all.
EDIT: After reading your comment I came to conclusion that you must have misunderstood the meaning and the purpose of the -Wmissing-prototypes
option and corresponding warning. Note, this option will not check whether you have included prototypes of all your functions into some header file. There is no option to do that in GCC, regardless of whether you are using C or C++.
The purpose of -Wmissing-prototypes
is different. This option only works when you call a function that has no visible prototype at the point of the call. In C language doing this is legal, but if you'd like a warning in this case, you use -Wmissing-prototypes
option. In C++ language calling a function that has no visible declaration ("prototype") at the point of the call is always an immediate error, which is why C++ compilers have no need for such option as -Wmissing-prototypes
.
In other words, if you defined some function in some implementation file, but forgot to include a prototype for this function in some header file, you will not get any warnings from the compiler until you actually try to call that function. It doesn't matter whether your code is C or C++, whether you use -Wmissing-prototypes
or not... Until you make an attempt to call the function, there will be no warnings.
But once you try to call a function without a prototype, the C compiler will report a warning (if you used -Wmissing-prototypes
) and C++ compiler will always report an error.