#Dealing with warnings with -Werror set

27 messages · Page 1 of 1 (latest)

wet bolt
#

So I generally like having my compiler give me as many warning/errors as possible, so I have -Wall -Werror -Wpedantic -Wextra set. Now, I have pedantic giving me a warning because apparently the \e escape in a string literal is not part of the C standard (though it is implemented in both GCC & Clang):

/home/chris/git/chris-monorepo/cpp/ipc-runner/server.cpp:19:11: error: use of non-standard escape character '\e' [-Werror,-Wpedantic]
   19 |   printf("\e[1;1H\e[2J");
      |           ^~

What is the best practice for allowing a particular offense? (In other languages I'm used to adding a special comment or a pragma to tell the compiler to skip the warning). I'm technically using C++ so a C++ pragma would work. I would also be ok telling the compiler to specifically skip this ONE check from the -Wpedantic set, however the compiler didn't even tell me the name of the check...

Alternatively, is there a way to write this in a spec-compliant way?

knotty baneBOT
#

-# C @light lava @heady oracle
-# C++ @brisk mirage @light lava @heady oracle

heady oracle
#

2 options:
make your string portable?

#

ig you could just

constexpr char ESC = '\x1b';
printf("%c[1;1H%c[2J", ESC, ESC);
wet bolt
#

ahh

heady oracle
#

(or just inline the \x1b)

wet bolt
#

ahh, I see, so in gcc/clang \e is equivalent to 0x1b

heady oracle
#

if you wanna suppress it you'll have to like pragma GCC diagnostic push then ignore the Wpedantic and then diagnostic pop

wet bolt
#

yeah, that's easier

heady oracle
#

not so nice tbh

wet bolt
#

oh dear

#

but, good to know in case i have to

heady oracle
#

We love using C++ 😭

wet bolt
#

and if you want that portable across clang also, you'd need more macro magic? or does that magicaly work with clang too?

heady oracle
#

I believe clang takes the GCC pragmas as well

#

💀

wet bolt
#

yeah

#

fun

heady oracle
#

shoulda used rust fr

wet bolt
#

oh, so #pragma gcc diagnostic push is like, "take a save state of the current diagnostic settings", then you mutate the diagnostics you want via other pragmas, then pop to restore it?

#

that's wild

heady oracle
#

yurp

wet bolt
#

it feels like C++ has every feature I would ever want, and yet I'm not happy with the way any of them are implemented...

#

anyway, thanks for the help, this is what I wanted to know

heady oracle
#

hop on the ocaml or rust grind 🌹

wet bolt
#

Yeah, OCaml is my favorite language