This is the mail archive of the gcc@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]

No pointer conversion warning for "bool" in C/C++


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;
}

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