tags:

views:

82

answers:

1

I'm quite surprised when I compile the following code without any warning using g++ 4.1.2 with -Wall -Wextra -Wconversion enabled.

I want g++ to show me every warning to avoid potential harm. I have to stick to g++ 4.1.2.

#include <stdint.h>
#include <string>

using namespace std;

int main()
{
    uint8_t u1=1;
    uint64_t u64=1000;
    string s1="";

    u1=u64; // want warning here
    s1=u64; // want warning here
    s1=u1;
}
+4  A: 

I'm afraid GCC before 4.3 doesn't seem to support this. The description of -Wconversion changed between 4.2 and 4.3 to reflect the new warning behavior, and there is no indication that pre-4.3 GCC would check for this.

Philipp
I can confirm it, gcc 4.3 produces warning, 4.2 does not
aaa
I can also confirm GCC 4.4 produces the warning, and only with `-Wconversion`enabled
rubenvb
Thx. Then I'll have to look for some static c++ code analysis tool.
lyman