Could the warning message below be revised to include a warning that NULL will
evaluate to false or zero?

In addition, is there a way to add the member name which is being initialised
to the warning? The line numbers are not accurate too, so it needs some
inspection to figure out the members concerned.

$ g++ -Wall -o t main.cpp
main.cpp: In constructor ‘A::A()’:
main.cpp:16: warning: converting to non-pointer type ‘bool’ from NULL
main.cpp:16: warning: converting to non-pointer type ‘int’ from NULL
main.cpp:16: warning: converting to non-pointer type ‘unsigned int’ from NULL


Could it be revised to display something like this?

$ g++ -Wall -o t main.cpp
main.cpp: In constructor ‘A::A()’:
main.cpp:16: warning: initialization of A::m_bool converts to non-pointer type
‘bool’ from NULL
main.cpp:16: warning: initialization of A::m_int converts to non-pointer type
‘int’ from NULL
main.cpp:16: warning: initialization of A::m_unit converts to non-pointer type
‘unsigned int’ from NULL



Example program:
=====================
// g++ -Wall -o t main.cpp
#include <string.h>

class A
{
        public:
        A();
        bool m_bool;
        int m_int;
        unsigned int m_uint;
};

A::A()
: m_bool(NULL),
m_int(NULL),
m_uint(NULL)
{
}

int main()
{       
}


-- 
           Summary: Clarify NULL pointer conversion to other types in
                    initialiser
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jg at jguk dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31755

Reply via email to