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

            bug437.cpp

1     #include <stdio.h>
2
3     class BagOfToys
4         {
5         int count;
6         const char *name;
7       public:
8         operator const char*() const { return name; }
9         BagOfToys( const char *n, int c ) :count(c), name(n) {}
10        };
11
12    int main()
13        {
14        BagOfToys johnny( "little Johnny", 10 );
15        printf( "This bag goes to %s\n", johnny );
16        return 0;
17        }

Whether this was the work of the Grinch or not we'll never know. But the program above has a serious flaw. Fortunately Santa was using PC-lint and the error was caught just in time.


bug437.cpp lint Output

--- Module:   bug437.cpp
    _
    };
bug437.cpp(10) : Info 1712: default constructor not defined for class
    'BagOfToys' 
                                            _
    printf( "This bag goes to %s\n", johnny );
bug437.cpp(15) : Warning 437: Passing struct 'BagOfToys' to ellipsis 
bug437.cpp(15) : Warning 560: argument no. 2 should be a pointer

--- Global Wrap-up

Info 1714: Member function 'BagOfToys::operator const char *(void) const' (line
    8, file bug437.cpp) not referenced

Reference Manual Explanation


437   Passing struct 'Symbol' to ellipsis  -- A struct is being passed to a 
      function at a parameter position identified by an ellipsis.  For example:

                void g()
                 {
                 struct A { int a; } x;
                 void f( int, ... );
                 f( 1, x );
                 ...

                 }

      This is sufficiently unusual that it is worth pointing out on the likelihood 
      that this is unintended.  The situation becomes more severe in the case of a 
      Non-POD struct  [10].  In this case the behavior is considered undefined.

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

Previous Bug - Bug #1557 - November 2003

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2003, Gimpel Software