[Bug c++/105130] New: gcc does not warn about unused return value of last expression of statement expr

dani at danielbertalan dot dev gcc-bugzilla@gcc.gnu.org
Fri Apr 1 19:55:36 GMT 2022


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

            Bug ID: 105130
           Summary: gcc does not warn about unused return value of last
                    expression of statement expr
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dani at danielbertalan dot dev
  Target Milestone: ---

Created attachment 52739
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52739&action=edit
Proposed patch

The following code does not cause a warning about the return value of the foo()
function being ignored:

$ cat unused.cc
[[nodiscard]] int foo();

int main() {
    ({ foo(); });
}

$ g++ -Wunused-value -std=c++20 unused.cc
[no warnings]

The issue seems to be that CLEANUP_POINT_EXPR and STATEMENT_LIST -- which are
what statement expressions are turned into -- are not handled in
convert_to_void() (cp/cvt.cc).

The attached patch resolves the issue, but as a newbie to hacking on gcc, I
can't evaluate if it has any unintended consequences.


More information about the Gcc-bugs mailing list