7

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; } 
5
  • 2
    I think you'll find the English phrase is "want to", not "wanna". Commented Jul 9, 2010 at 7:42
  • And you don't want a warning on the last line? What is the intended meaning of assignment from unsigned char to string? Commented Jul 9, 2010 at 7:52
  • @David: string has operator=(char). Commented Jul 9, 2010 at 8:00
  • 2
    So you also need -Wsign-conversion. I think it's time for -Wall-but-this-time-for-real. O my. Commented Jul 9, 2010 at 8:06
  • @Georg: thanks I failed to check for that. I have never used it and did not think that would be supported. Commented Jul 9, 2010 at 8:28

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.