Bug 87408 - Enhance -Wunused-value to catch more complex expressions
Summary: Enhance -Wunused-value to catch more complex expressions
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning Wunused
  Show dependency treegraph
 
Reported: 2018-09-24 10:51 UTC by Martin Liška
Modified: 2021-04-10 18:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-09-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2018-09-24 10:51:54 UTC
For the following example:

$ cat /tmp/test.C
struct A
{
  int a;
};

A mya;

static A *get() { return &mya; }

int main()
{
  A *p = get ();
  p->a; // issue #1

  get ()->a; // issue #2

  return 0;
}

GCC only catches only one issue, clang both of them:

$ g++ /tmp/test.C -Wall -Wextra
/tmp/test.C: In function ‘int main()’:
/tmp/test.C:13:6: warning: statement has no effect [-Wunused-value]
   p->a;
   ~~~^

$ clang++ /tmp/test.C -Wall -Wextra
/tmp/test.C:13:6: warning: expression result unused [-Wunused-value]
  p->a;
  ~  ^
/tmp/test.C:15:11: warning: expression result unused [-Wunused-value]
  get ()->a;
  ~~~~~~  ^
Comment 1 Jonathan Wakely 2018-09-24 11:12:35 UTC
Our warning talks about the statement, and without interprocedural analysis it can't see that get() doesn't have an effect. Clang's warning is better because it doesn't say anything about whether get() has an effect, just that get()->a doesn't use the result of the class member access.
Comment 2 Eric Gallager 2018-10-01 04:22:06 UTC
I thought this might be a dup of something, but the closest things I can find are bug 66658, bug 58950, and bug 64639, but none of them are quite what I was looking for and are only "related" at best...