This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

middle-end/9063: invalid compile-time evaluation of tertiary expression


>Number:         9063
>Category:       middle-end
>Synopsis:       invalid compile-time evaluation of tertiary expression
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 27 00:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Travis Geiselbrecht
>Release:        gcc version 3.2.2 20021212 (Debian prerelease)
>Organization:
>Environment:
Debian Linux 3.0 testing. x86 pc
>Description:
The following minimal program will reproduce if compiled with 
any levels of optimization. 

Problem:
the expression (100000 + 1 ? 99 : 0) takes on a value of '99',
instead of the expected 100099. A simple addition of parenthesis
to produce (100000 + (1 ? 99 : 0)) produces the proper result.

Not incredibly serious, but I bumped into it and took a while to
figure out. Reproduced on 2.95.4, 3.0.4, and this 3.2.2 pre-release
version in debian. Originally seen on 3.0.4 i386.
>How-To-Repeat:
# 1 "bug.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "bug.c"


int main()
{
        printf("value of expression %d should be %d\n", (100000 + 1 ? 99 : 0), (100000 + (1 ? 99 : 0)));
        return 0;
}
>Fix:
Add parentheses around the tertiary operator.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]