Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug1563.cpp

1    #include <stdio.h>
2
3    const char *Jane = "";
4    const char *The_Poor = "";
5
6    void assign_gift(bool naughty)
7        {
8        naughty ? The_Poor : Jane =
9                  "New Bicycle";
10       }
11
12   int main()
13       {
14       assign_gift(true);
15       printf( "The Poor = '%s', Jane = '%s'\n",
16                The_Poor, Jane );
17       return 0;
18       }

This is just a small portion of a vast computer program being prepared by Santa and his elves. Unfortunately something is going wrong and even though Jane has been naughty, the poor are still "left with nothing". What's going wrong?


bug1563.cpp lint Output

--- Module:   bug1563.cpp (C++)
                           _
              "New Bicycle";
bug1563.cpp(9) : Warning 1563: Suspicious third argument to ?: operator

Reference Manual Explanation


1563   Suspicious third argument to ?: operator  -- The third argument
       to ?: contained an unparenthesized assignment operator such as

                 p ? a : b = 1

       If this is what was intended you should parenthesize the third
       argument as in:

                 p ? a : (b = 1)

       Not only is the original form difficult to read but C, as opposed
       to C++, would parse this as:

                 (p ? a : b) = 1


If you have comments or questions about this bug, please post them to our   Discussion Forum


Previous Bug - Bug #456 - November 2010

Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2010, Gimpel Software, All rights reserved.