Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(203)

Issue 4444068: Warn on constants in logical expressions (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 7 months ago by rtrieu
Modified:
13 years, 5 months ago
Reviewers:
chandlerc
Base URL:
https://llvm.org/svn/llvm-project/cfe/trunk/
Visibility:
Public.

Description

Warn on code such as: return x || 5; Submitted at revision 132327.

Patch Set 1 #

Total comments: 4

Patch Set 2 : C test cases with 1 and 0 without warning. #

Total comments: 4

Patch Set 3 : Changed test cases to include paren and non-paren cases. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+59 lines, -8 lines) Patch
M lib/Sema/SemaExpr.cpp View 1 1 chunk +8 lines, -6 lines 0 comments Download
M test/CodeGenCXX/static-init-2.cpp View 1 chunk +1 line, -1 line 0 comments Download
M test/Sema/exprs.c View 1 2 1 chunk +18 lines, -0 lines 0 comments Download
M test/SemaCXX/expressions.cpp View 1 2 1 chunk +31 lines, -0 lines 0 comments Download
M test/SemaCXX/switch.cpp View 1 2 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 4
chandlerc
http://codereview.appspot.com/4444068/diff/1/test/SemaCXX/expressions.cpp File test/SemaCXX/expressions.cpp (right): http://codereview.appspot.com/4444068/diff/1/test/SemaCXX/expressions.cpp#newcode43 test/SemaCXX/expressions.cpp:43: return x || false; It'd be good to add ...
13 years, 6 months ago (2011-05-26 10:17:17 UTC) #1
rtrieu
http://codereview.appspot.com/4444068/diff/1/test/SemaCXX/expressions.cpp File test/SemaCXX/expressions.cpp (right): http://codereview.appspot.com/4444068/diff/1/test/SemaCXX/expressions.cpp#newcode43 test/SemaCXX/expressions.cpp:43: return x || false; On 2011/05/26 10:17:17, chandlerc wrote: ...
13 years, 6 months ago (2011-05-28 01:45:08 UTC) #2
chandlerc
Please go ahead and mail this to cfe-commits. I want to give folks a chance ...
13 years, 6 months ago (2011-05-28 07:17:31 UTC) #3
rtrieu
13 years, 6 months ago (2011-05-29 19:41:24 UTC) #4
http://codereview.appspot.com/4444068/diff/4001/test/SemaCXX/expressions.cpp
File test/SemaCXX/expressions.cpp (right):

http://codereview.appspot.com/4444068/diff/4001/test/SemaCXX/expressions.cpp#...
test/SemaCXX/expressions.cpp:51: return x || (-1); // expected-warning {{use of
logical || with constant operand; switch to bitwise | or remove constant}}
On 2011/05/28 07:17:31, chandlerc wrote:
> FYI, i'd only use parentheses where it matters or in one place that is clearly
> just testing their removal with (((x))), etc. The reason is I keep thinking
> they're significant here for some reason...

Duplicated the test cases without the parens.

http://codereview.appspot.com/4444068/diff/4001/test/SemaCXX/switch.cpp
File test/SemaCXX/switch.cpp (right):

http://codereview.appspot.com/4444068/diff/4001/test/SemaCXX/switch.cpp#newco...
test/SemaCXX/switch.cpp:12: switch (n && m) { // expected-warning {{bool}}
On 2011/05/28 07:17:31, chandlerc wrote:
> Why not just 'n && true' here?

Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b