[PATCH] D77611: [Sema] Check calls to __attribute__((warn_unused_result)) from StmtExprs

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 9 14:11:00 PDT 2020


dblaikie added a comment.

In D77611#1968236 <https://reviews.llvm.org/D77611#1968236>, @nickdesaulniers wrote:

> In D77611#1968227 <https://reviews.llvm.org/D77611#1968227>, @dblaikie wrote:
>
> > Looks like GCC warns on everything but the last unused expression (the last one being the return statement) - only warning on that last one if it's ultimately unused by the statement expression function call, as it were (& is annotated warn_unused_result). Basically, it models it like a function in a way that Clang perhaps does not?
>
>
> For the case of warn_unused_result, it doesn't matter whether the unused call is the first or last statement in the statement expression: https://godbolt.org/z/DDgsVC (notice that trunk of LLVM warns now, just not for the return value case from my added test).


Not sure I follow - if you swap the statements in the example there, the warning seems to go away. Compare (yours) https://godbolt.org/z/DDgsVC (warning with Clang and GCC) with https://godbolt.org/z/j65QXo (Clang and GCC do not warn).

> So GCC treats the return value from statement expressions differently from return values from functions in this regard: https://godbolt.org/z/83wP7W

I don't think it does (based on above clarification/test cases). But your change would make Clang treat them differently from each other (& different from GCC), I think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77611/new/

https://reviews.llvm.org/D77611





More information about the cfe-commits mailing list