Disable GCC “may be used uninitialized” on a particular variable

前端 未结 5 566
故里飘歌
故里飘歌 2021-02-01 03:09

I\'m getting this warning on a stack variable:

warning: object.member may be used uninitialized in this function

In this case I do not wish to

5条回答
  •  深忆病人
    2021-02-01 03:44

    The accepted answer has two big problems that requires more than a comment. First, it deactivates the warning for the whole file. If that pragma resides in a header, probably for more. Warnings are useful and if it is indeed a false positive, one should disable the warning for a bunch of code as small as possible.

    Then the warning in the OP is "maybe uninitialized" which is deactivated by -Wmaybe-uninitialized, as opposed to -Wuninitialized.

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
    function() or int variable;
    #pragma GCC diagnostic pop
    

提交回复
热议问题