Skip to content

False -Wunreachable-code warning in conditional expression #10146

@markus-oberhumer

Description

@markus-oberhumer
Bugzilla Link 9774
Resolution FIXED
Resolved on Jan 03, 2012 15:02
Version trunk
OS Linux
CC @tkremenek

Extended Description

The following typescript shows that clang incorrectly warns about
unreachable code when using the ternary "if" operator:

$ cat test.c
#define MY_MAX(a,b) ((a) >= (b) ? (a) : (b))

void foo(int *s)
{
for (int i = 0; i < MY_MAX(2, 3); i++)
s[i] = 0;
}

$ clang -Wunreachable-code -c test.c
test.c:5:25: warning: will never be executed [-Wunreachable-code]
for (int i = 0; i < MY_MAX(2, 3); i++)
^~~~~~~~~~~~
test.c:5:32: note: instantiated from:
for (int i = 0; i < MY_MAX(2, 3); i++)
^
1 warning generated.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions