Bug 42406 - gcc issues warning with tolower function with optimization flag
Summary: gcc issues warning with tolower function with optimization flag
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-17 15:02 UTC by joe.bassis
Modified: 2009-12-17 16:20 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description joe.bassis 2009-12-17 15:02:26 UTC
gcc issues warning when using the tolower function along with an optimization flag. This warning also happens in other versions of gcc apart from 4.4.2

gcc -std=c99 -pedantic -O2 -Wall -Wunreachable-code a.c

a.c:13: warning: will never be executed



#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    char A[50] = "";
    strcat(A, "Hello World!");

    int COUNT = 0;
    while(A[COUNT])
    {
        A[COUNT] = (char)(tolower(A[COUNT])); // this line issues warning
        COUNT++;
    }
    puts(A); // output: hello world!
    return 0;
}
Comment 1 Richard Biener 2009-12-17 16:20:26 UTC
-Wunreachable-code is broken and has been removed in 4.5.