[Bug c/94389] New: __attribute__((warn_unused_result)) will warn if the result is discarded as an optimisation

felix.von.s at posteo dot de gcc-bugzilla@gcc.gnu.org
Sun Mar 29 15:36:12 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94389

            Bug ID: 94389
           Summary: __attribute__((warn_unused_result)) will warn if the
                    result is discarded as an optimisation
           Product: gcc
           Version: 9.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.von.s at posteo dot de
  Target Milestone: ---

With the code below, the compiler warns about an unused result, even though the
result is used:

    #define O_TEXT 0  /* defined on Windows and DOS, but not needed on Unix */

    __attribute__((warn_unused_result))
    extern int text_mode(void);

    int get_flags(void) {
        return text_mode() ? O_TEXT : 0;
    }

Similarly, there is a warning if the result of a function marked with
__attribute__((warn_unused_result)) is multiplied by 0, and probably with other
expressions that are easily constant-folded. If the function also has
__attribute__((const)), there is no warning.

I think this issue could be resolved as a by-product of fixing bug 66425.


More information about the Gcc-bugs mailing list