Bug 59819 - -Wunused-value reports incorrect values as unused
Summary: -Wunused-value reports incorrect values as unused
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 trivial
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wunused
  Show dependency treegraph
 
Reported: 2014-01-15 06:31 UTC by Brandon Captain
Modified: 2021-09-16 21:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
The program in full to replicate this bug (346 bytes, text/x-c++src)
2014-01-15 06:31 UTC, Brandon Captain
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brandon Captain 2014-01-15 06:31:11 UTC
Created attachment 31836 [details]
The program in full to replicate this bug

This is pretty trivial but the warning outputs incorrect information. given the line:

int foo = static_cast< int >( 1, 2, 3 );

G++ reports that value 2 and 3 are not used, when in fact 1 and 2 are not used.

G++ 4.8.1's output (with -Wall):
test.cpp: In function ‘int main()’:
test.cpp:15:35: warning: left operand of comma operator has no effect [-Wunused-value]
  int foo = static_cast< int >( 1, 2, 3 );
                                   ^
test.cpp:15:38: warning: right operand of comma operator has no effect [-Wunused-value]
  int foo = static_cast< int >( 1, 2, 3 );
                                      ^


Clang 3.2.7 gets it right, however:

test.cpp:15:32: warning: expression result unused [-Wunused-value]
        int foo = static_cast< int >( 1, 2, 3 );
                                      ^
test.cpp:15:35: warning: expression result unused [-Wunused-value]
        int foo = static_cast< int >( 1, 2, 3 );
                                         ^
2 warnings generated.