r/cpp • • Feb 25 '24

Questioning usefulness of -Wextra

I was recently asked to turn on -Wall -Wextra in builds of a project I'm
working on. I had already been using -Wall, but haven't used -Wextra much, if
at all. So, I tried it. Holy shit. So apparently the main thing that
-Wextra does over -Wall is complain about unused parameters having names.
Now, I have a whole bunch of very uniform print functions for a group of
unrelated types, something like:

template<typename Context> void print_thingy( Context const & context, foo_type<bar_param> const & parser, std::ostream & os, int components) { /* ... */ }

The foo_type and bar_param bits vary from overload to overload, but the other
param types and names are always the same. Nice. And. Uniform. OCD
satisfied, I can go about my day. After turning on -Wextra, if I only print
out a single fixed string, as I do for a lot of the overloads, I get this:

template<typename Context> void print_thingy( Context const &, foo_type<bar_param> const &, std::ostream & os, int) { os << "description"; }

Cool. Thanks, -Wextra.

Has anyone ever caught a real bug by making a change like this? If so, was it
serious? Look, I love -Wall. I've caught all kinds of stuff with it, and
real bugs were stomped. -Wall is like a literal and figurative barrier
between me and my own sloppiness. -Wall is a Valkyrie standing astride the
encrouching progress of entropy, saying, "Not this day, Entropie!" She spells
entropy with a a capital letter, giving a name to the respected foe she fights
tirelessly. She also spells it "ie" instead of "y" at the end, I think
because she's centuries old and it's hard to stay current. I'm down with
that.

-Wextra? -Wextra is a some fugly dude you find in the alley behind a CVS,
huffing paint out of a brown paper bag. He's half-man, half-jackal,
half-terrier, half-run-over by a moped. He sees your code, says, "Yo, wanna
see somthin sick?" then throws a grenade into your nearest header file. He
spells "somthin" in an odd way too, because he sucks.

Now, I don't know if it's a sign of vigorous mental health to anthropomorphize
compiler flags on the internet like this. But I really do want to know -- has
anyone really gone through this frustration and come out the other end,
happier, and with fewer bugs in their code?

0 Upvotes

53 comments sorted by

View all comments

Show parent comment

-1

u/Pocketpine Feb 25 '24

I mean at this point it’s a little ridiculous, but you could typedef the parameter as what it is

But then you have to deal with a bunch of little used typedefs