Hello

Currently gcc, and g++ don't give a warning when a pointer was converted to a bool, in the same way it is for other types.

Could I ask for opinion on this, and if I should create a bug ticket.

Please find below output from compilation, and attachments showing the two tests.

gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2

$ gcc -Wconversion -Wall -o t bool_conversion.c
bool_conversion.c: In function ‘main’:
bool_conversion.c:14:8: warning: assignment makes integer from pointer without a cast bool_conversion.c:15:9: warning: assignment makes integer from pointer without a cast

^ I expected to see a warning on line 13.



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

^ I expected to see a bool warning on line 16.


I tested assigning NULL in these tests (Note, I also confirmed that assigning a pointer variable produced the same lack of warning output.)

Please include my email address in any replies

Best regards, Jon
// g++ -Wconversion -o t main.cpp
// Should this not give a warning for the bool conversion
// include to get definition of NULL
#include <string.h>


void * g_glob = NULL;
class A
{
public:
	A();
	bool m_bool;
	int m_int;
	unsigned int m_uint;
};

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

int main()
{
	return 0;       
}

// gcc -Wconversion -o t bool_conversion.c
// Should this not give a warning for the bool conversion
// include to get definition of NULL
#include <string.h>
#include <stdbool.h>

int main(void)
{
	bool m_bool;
	int m_int;
	unsigned int m_uint;

	m_bool = NULL;
	m_int = NULL;
	m_uint = NULL;

	return 0;
}

Reply via email to