gcc helpfully distinguishes between -Wswitch, which warns about missing
enumeration cases /unless/ there is a default clause, and -Wswitch-enum
which will warn even if there is a default. -Wswitch is the useful one
in almost all cases. If gcc only had "-Wswitch-enum", then I'd agree it
is was silly, and only enable it manually (with pragmas) in situations
where it would be really helpful.
> With Visual C++ 2017 that warning, C4061, has been /turned off/ by
> default. Presumably for the same reason as my sillywarnings-list. See
> the list at
> <
https://docs.microsoft.com/en-us/cpp/preprocessor/compiler-warnings-that-are-off-by-default>;
> as it happens this warning is on top.
>
> I think this shows that for this particular concrete example you're
> arguing from ignorance, due to simply not having much experience with
> this compiler and its idiosyncrasies.
>
This case is ignorance of the details - I have not claimed any knowledge
of the MSVC warnings beyond the comments in your list.
>
>> I don't put functions in my code that are not used - I write for small
>> embedded systems, and don't want to waste space.
>>
>> If I mark a function as "inline", and it is not inlined, I want to
>> know about it. (But I don't care if a normal function /is/ inlined by
>> the compiler.)
>
> `inline`'s effect on inlining of calls is just a hint. Its main purpose,
> and its only guaranteed effect, is to ensure that a function can be
> defined in a header; technically, that it can be defined in the same
> way, with extern linkage, in multiple translation units. When the
> keyword is used for that guaranteed effect, or when a member function is
> defined in the class definition (which implicitly gives it `inline`),
> you really don't want the compiler spewing out diagnostics about
> ignoring the additional vague hint semantics.
I do want these, yes - at least for my own code. If I declare a
function "inline", then I want it to be inlined by the compiler. If I
did not think it /could/ be inlined - for example, if I wanted to take
its address, or call it recursively - then I would not have marked it
"inline". I don't want functions declared in headers that result in
code generation on their own (excluding templates here). So if the
compiler is unable to inline a function that I have marked "inline", I
have made a mistake somewhere - either in how I use the function, what
the function does, or in labelling it "inline". To me, "inline" is as
much documentation to the reader as a hint to the compiler, and it
should match the compiler's viewpoint.
Of course other people can have a different opinion here - but to /me/,
warning on a failure to inline is a useful warning, not a silly one.
>
> So here you're evidently doing something wrong.
>
> Where you want an all-out effort to inline a call (I think it's better
> to let the compiler decide, but let's say profiling says that the
> compiler didn't inline where it should, and that it's critical), use the
> appropriate compiler specific magic invocation. Standard C++ doesn't
> have that feature; relying on `inline` to do /that/ job is not portable.
> But the compiler-specific can be wrapped in a macro for portability.
I use the appropriate compiler-specific "magic words" sometimes to force
inlining. A typical case is when I know that constant propagation will
mean that a function that /looks/ big and complex (and therefore the
compiler might decide against inlining) will turn into something small
and short in practice. Or perhaps the function is to be used within
critical sections of some sort (like interrupt functions - I work on
low-level embedded systems) and I want to keep it as fast as possible.
That is a different situation, however.
(And as I say, I am quite happy to let the compiler inline functions
that are /not/ marked inline, and don't feel a need for a warning there.
Indeed, I /expect/ the compiler to do such inlining, especially for
local functions that are only called once.)
>
> This warning, C4710, is also off by default in Visual C++ 2017.
>
>
>> If padding is added to a struct, I want to know about it.
>
> No, really, you don't. Padding is added to most structs. Only if you
> have designated the struct as packed, is such a warning useful.
Yes, really, I /do/ want this warning. And /no/, I don't want to mark
the struct as "packed". Feel free to express your own opinions, but
please do not try to tell me /my/ opinions. In my world, precise
control of exactly how data is organised can be important - it is
important enough that I prefer to have this warning and explicitly add
"padding" fields to my structs and necessary. I don't /always/ use this
warning, but I often do.
Now, I fully agree that it is unlikely that /you/ want this warning.
For user-mode programming on a large system, it is going to be rare that
you need this kind of control of structure layout. And you will get
massive numbers of false positives from common OS and API include files.
So for the typical MSVC user, it is probably useless. In the few cases
where it makes sense, you can enable it temporarily with pragmas.
My point is merely that this warning, viewed as a static analysis tool,
is not "silly" or "useless" in C and C++ development - it has its place.
>
> And also this warning, C4820, is one of those that now are off by default.
>
> I.e. for the three warnings so far, Microsoft have, wisely IMHO, agreed
> with the sillywarnings list. :-)
>
>
>> It is probably fair to say that disabling most of the warnings on your
>> list would not be a problem to me. It is unlikely that they would be
>> triggered by my code (after all, most of what I write is C rather than
>> C++!). And I think if, for example, a copy constructor cannot be
>> generated for a class, then that is because of the way you have
>> written the class.
>
> No, that could be e.g. `boost::noncopyable`.
Presumably, this class is written specifically in a way to make it
non-copyable and to mean that "a copy constructor cannot be generated
for this class". Maybe I was not quite clear in how I expressed myself,
because we appear to agree.
>
>
>> It is only a problem if the copy constructor cannot be generated, and
>> you need to use it - /that/ is when there needs to be a warning or error.
>
> Yes, I agree, but Visual C++ has had a habit of emitting these
> diagnostics whenever, as it looks from a purely local context ignoring
> everything else, they /might/ apply.
Indeed. It sounds to me that this example /is/ a "silly warning".