top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to make gcc warn about arithmetic signed overflow?

+1 vote
482 views
How to make gcc warn about arithmetic signed overflow?
posted Sep 21, 2013 by Bob Wise

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

If ab and bc are 'const' then G++ will warn:

o.cc: In function ‘int main()’:
o.cc:5:14: warning: integer overflow in expression [-Woverflow]
 int r = ab * bc;
 ^

The C compiler still doesn't warn though, due to different rules for how constants are handled between C and C++.

answer Sep 21, 2013 by Sumit Pokharna
Yes, gcc the Gnu Compiler Collection can produce such a warning:

procedure test_ovf is
 ab : integer := 50000;
 bc : integer := 50000;
 r : integer := ab * bc;
begin
 null;
end test_ovf;

gcc -c test_ovf.adb
test_ovf.adb:4:22: warning: value not in range of type "Standard.Integer"
test_ovf.adb:4:22: warning: "Constraint_Error" will be raised at run time
However I'm not sure it is allowed to do the same with C.
Similar Questions
0 votes

I'm studying about C compiler for increasing software quality. So I want to get all of compile error message list of gcc about C language. I was trying to find it. But I can't find it anywhere. How can I find it?

Please help?

+1 vote

I don't really understand this option. I enabled it but it warns for essentially all of my classes which have any virtual methods. For
example if I have Foo.h:

 class Foo {
 virtual bool bar();
 ...
 };

then Foo.cpp which implements Foo. And then in another header somewhere else I inherit from Foo and implement bar() differently (as a virtual function). However when GCC compiles Foo.cpp it can't see the other header, so I guess it assumes no one inherits from Foo and suggests it should be marked final:

Declaring type 'class Foo' final would enable devirtualization of N calls

I mean sure, it would, but that would defeat the entire point (as I understand it).

I don't really understand how/where this option is meant to be used.
Ditto for -Wsuggest-final-methods.

+5 votes

GCC is stripping the object file when nothing from the file is being used anywhere in the executable (even -o0 does nor help). We have to disable this feature of linker g++. could any one please help us to resolve this issue??

...