Announcement

Collapse
No announcement yet.

GCC Unlikely To Adopt A "-Weverything" For Exposing All Possible Code Warnings

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by bison View Post

    I use it for temporarily disabling the error handler in Xlib. The API requires a display pointer parameter, so the options are 1) do some sort of no-op with the display pointer parameter to make the compiler shut up, or 2) use -Wunused-parameter.
    Your comment prompted me to look for a GCC option to selectively disable warnings on a part of code. It looks like you can do it:

    https://gcc.gnu.org/onlinedocs/gcc/D...c-Pragmas.html

    So I think you could do:

    Code:
    #pragma GCC diagnostic ignored "-Wunused-parameter"
    
    void foo(int a, int b, int my_unused_display_pointer_param) {
    ...
    }
    
    #pragma GCC diagnostic warning "-Wunused-parameter"
    Note: I haven't tested that.

    Comment


    • #22
      Originally posted by cybertraveler View Post
      It's their decision but I personally like the idea of being able to specify -Weverything and then individually disable the specific warnings that I don't want. So it would effectively put GCC into a "all warnings by default" mode instead of a "no (or very few) warnings by default mode". So you have to toggle off options instead of toggle them on.
      That is basically what "-Wall -Wextra" does, enable everything that makes sense generally. The rest are supposed to be very specific things that is useless or outright harmful for the average project. If some generally useful warnings are missing from those two, it should be added there.

      Comment


      • #23
        Originally posted by carewolf View Post

        That is basically what "-Wall -Wextra" does, enable everything that makes sense generally. The rest are supposed to be very specific things that is useless or outright harmful for the average project. If some generally useful warnings are missing from those two, it should be added there.
        Can they add new types of warnings to those warning-set options or would that be considered as breaking break backwards compatibility?

        Comment


        • #24
          Originally posted by AHSauge View Post
          (...) Say what you want about packed structs, but in C they are sadly quite required in some context and this is a fairly easy pit to fall into. Yet, it takes about 7-8 years to implement it. I'll leave it up to the reader to determine the GCC developers attitude about this.
          (...) Why is it so damn hard to just allow everything to be exposed if the person compiling wants it?!
          Not trolling, but here's what Eric S. Raymond has to say [1] in this regard about Rust:
          Rust follows C-like field alignment rules if a structure is annotated with "repr(C)". Otherwise (by default) all bets are off: padding rules are (deliberately) unspecified and the compiler may even reorder structure members. It is probably best to let the Rust compiler do space optimization rather than forcing it.
          Is Rust better than C in this regard?


          [1]

          Comment


          • #25
            Originally posted by cybertraveler View Post

            Your comment prompted me to look for a GCC option to selectively disable warnings on a part of code. It looks like you can do it:

            https://gcc.gnu.org/onlinedocs/gcc/D...c-Pragmas.html

            So I think you could do:

            Code:
            #pragma GCC diagnostic ignored "-Wunused-parameter"
            
            void foo(int a, int b, int my_unused_display_pointer_param) {
            ...
            }
            
            #pragma GCC diagnostic warning "-Wunused-parameter"
            Note: I haven't tested that.
            I did, and it works. Thanks for the suggestion.

            I haven't tried compiling the code with clang, but hopefully it will ignore gcc pragmas, which is what I would expect it to do.

            Comment


            • #26
              In large projects, it's basically impossible to globally throw -Wall -Wextra without a bunch of -Wno-* waivers. Because of external code that can't be changed.

              Comment


              • #27
                Originally posted by AHSauge View Post
                I can't say I'm surprised, but man this is some real shitty usability. One would expect -Wall to have all relevant warnings for the platform, but unfortunately that's not the case. I don't know about bleeding edge GCC, but the one used at work needs -Wcast-align specifically set to expose alignment issues in the code. Worst yet, this bug report tells you how little they care about the issue. Say what you want about packed structs, but in C they are sadly quite required in some context and this is a fairly easy pit to fall into. Yet, it takes about 7-8 years to implement it. I'll leave it up to the reader to determine the GCC developers attitude about this.

                Regardless, it's sad that this kind of stubborn attitude exists. In my case I simply have to enable alignment fault error on the ARM chip and find all the misaligned read and writes in runtime. It's a fairly shit approach as a result of the lack of option to make the compiler report all warnings it knows about. Why is it so damn hard to just allow everything to be exposed if the person compiling wants it?!
                What is the problem that you have with packed structs? I use packed structs extensively for on the wire protocols with thousands of external sources and have never once encountered a problem with packed structs in GCC and that is going back to 2.x when I begun to use GCC.

                Code:
                struct OrderbookDirectory {
                        char MessageType;
                        uint32_t Nanoseconds;
                        uint32_t OrderbookID;
                        char Symbol[32];
                        char Name[32];
                        char ISIN[12];
                        uint8_t FinancialProduct;
                        char TradingCurrency[3];
                        uint16_t NumberOfDecimalsInPrice;
                        uint16_t NumberOfDecimalsInNominalValue;
                        uint32_t OddLotSize;
                        uint32_t RoundLotSize;
                        uint32_t BlockLotSize;
                        uint64_t NominalValue;
                } [B]__attribute__ ((packed))[/B] __attribute__((__may_alias__));

                Comment


                • #28
                  Originally posted by carewolf View Post
                  Why? Just don't name parameters you don't use.
                  That works only in C++ AFAIK, not in C.

                  Comment


                  • #29
                    Originally posted by cybertraveler View Post

                    Can they add new types of warnings to those warning-set options or would that be considered as breaking break backwards compatibility?
                    They add new warnings to them all the time. Several project I work on use -Wall -Wextra -Werror, and one the things that combination requires is maintainence fixing or silencing all the new warnings in every compiler release.

                    Comment


                    • #30
                      Originally posted by cybertraveler View Post

                      Your comment prompted me to look for a GCC option to selectively disable warnings on a part of code. It looks like you can do it:

                      https://gcc.gnu.org/onlinedocs/gcc/D...c-Pragmas.html

                      So I think you could do:

                      Code:
                      #pragma GCC diagnostic ignored "-Wunused-parameter"
                      
                      void foo(int a, int b, int my_unused_display_pointer_param) {
                      ...
                      }
                      
                      #pragma GCC diagnostic warning "-Wunused-parameter"
                      Note: I haven't tested that.
                      Better to push diagnostics before, then pop after, so the rest of the code follows the build system flags (where diagnostics are supposed to be controlled!). So:
                      Code:
                      #pragma GCC diagnostic push
                      #pragma GCC diagnostic ignored "-Wunused-parameter"
                      
                      void foo(int a, int b, int my_unused_display_pointer_param) {
                      ...
                      }
                      
                      #pragma GCC diagnostic pop
                      -e- And if you wish for portability, you're going to want to surround those pragmas with some #if too.
                      Last edited by brrrrttttt; 24 January 2019, 10:35 PM.

                      Comment

                      Working...
                      X