Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

85%
+10 −0
Q&A Scheme for cross-platform warning control?

tl;dr I'd like to learn a compact, cross-compiler way of selectively suppressing compiler warnings. Consider the case where you really mean to make an exact floating-point comparison using ==, o...

1 answer  ·  posted 3y ago by dmckee‭  ·  last activity 3y ago by Someone‭

#2: Post edited by user avatar Alexei‭ · 2021-01-22T07:33:22Z (over 3 years ago)
added relevant tags
  • **tl;dr** I'd like to learn a compact, cross-compiler way of selectively suppressing compiler warnings.
  • ---
  • Consider the case where you really mean to make an exact floating-point comparison using `==`, or the case where you capture a return value that you don't use in production but want to `assert` on in debug.
  • If you are running your compiler with a highly level of feedback you're going to get a warnings from the first all the time and from the second when performing a release build.
  • Now, most compilers have a way to annotate a symbol to let the compiler know you're aware of the situation (for instance `__attribute__((unused))` in gcc), and various pre-processor pragmas to adjust the compilation envrionment. But we have three compilers to worry about (gcc and msvc for actually building the code on different target platforms and clang as a linter on both).
  • In some places we actually have painfully heavy and intrusive pre-processor constructs like:
  • ```c++
  • #if defined(_MSC_VER)
  • #pragma warnings(push)
  • #pramga warnings(disable : 123456)
  • #elif defined(__clang__)
  • #pragma clang diagnostic push
  • #pramga clang diagnostic ignored "-Wluggage-combination"
  • #elif defined(__GNUC__)
  • #pragma GCC diagnostic push
  • #pramga GCC diagnostic ignored "-Wcode-for-my-luggage"
  • #endif
  • // Offending line(s) of code
  • #if defined(_MSC_VER)
  • #pragma warnings(pop)
  • #elif defined(__clang__)
  • #pragma clang diagnostic pop
  • #elif defined(__GNUC__)
  • #pragma GCC diagnostic pop
  • #endif
  • ```
  • Which, though ugly as sin, works and doesn't cause too much nausea if it occurs once in a low-level module that you don't touch often.
  • But I feel that it should be easier and neater.
  • Anyone have a working solution?
  • []()**tl;dr** I'd like to learn a compact, cross-compiler way of selectively suppressing compiler warnings.
  • ---
  • Consider the case where you really mean to make an exact floating-point comparison using `==`, or the case where you capture a return value that you don't use in production but want to `assert` on in debug.
  • If you are running your compiler with a highly level of feedback you're going to get a warnings from the first all the time and from the second when performing a release build.
  • Now, most compilers have a way to annotate a symbol to let the compiler know you're aware of the situation (for instance `__attribute__((unused))` in gcc), and various pre-processor pragmas to adjust the compilation envrionment. But we have three compilers to worry about (gcc and msvc for actually building the code on different target platforms and clang as a linter on both).
  • In some places we actually have painfully heavy and intrusive pre-processor constructs like:
  • ```c++
  • #if defined(_MSC_VER)
  • #pragma warnings(push)
  • #pramga warnings(disable : 123456)
  • #elif defined(__clang__)
  • #pragma clang diagnostic push
  • #pramga clang diagnostic ignored "-Wluggage-combination"
  • #elif defined(__GNUC__)
  • #pragma GCC diagnostic push
  • #pramga GCC diagnostic ignored "-Wcode-for-my-luggage"
  • #endif
  • // Offending line(s) of code
  • #if defined(_MSC_VER)
  • #pragma warnings(pop)
  • #elif defined(__clang__)
  • #pragma clang diagnostic pop
  • #elif defined(__GNUC__)
  • #pragma GCC diagnostic pop
  • #endif
  • ```
  • Which, though ugly as sin, works and doesn't cause too much nausea if it occurs once in a low-level module that you don't touch often.
  • But I feel that it should be easier and neater.
  • Anyone have a working solution?
#1: Initial revision by user avatar dmckee‭ · 2021-01-20T20:19:44Z (over 3 years ago)
Scheme for cross-platform warning control?
**tl;dr** I'd like to learn a compact, cross-compiler way of selectively suppressing compiler warnings.

---

Consider the case where you really mean to make an exact floating-point comparison using `==`, or the case where you capture a return value that you don't use in production but want to `assert` on in debug.

If you are running your compiler with a highly level of feedback you're going to get a warnings from the first all the time and from the second when performing a release build.

Now, most compilers have a way to annotate a symbol to let the compiler know you're aware of the situation (for instance `__attribute__((unused))` in gcc), and various pre-processor pragmas to adjust the compilation envrionment. But we have three compilers to worry about (gcc and msvc for actually building the code on different target platforms and clang as a linter on both).

In some places we actually have painfully heavy and intrusive pre-processor constructs like:
```c++
#if defined(_MSC_VER)
#pragma warnings(push)
#pramga warnings(disable : 123456)
#elif defined(__clang__)
#pragma clang diagnostic push
#pramga clang diagnostic ignored "-Wluggage-combination"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pramga GCC diagnostic ignored "-Wcode-for-my-luggage"
#endif

    // Offending line(s) of code

#if defined(_MSC_VER)
#pragma warnings(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

```
Which, though ugly as sin, works  and doesn't cause too much nausea if it occurs once in a low-level module that you don't touch often.

But I feel that it should be easier and neater.

Anyone have a working solution?
c++