Skip to content
Snippets Groups Projects
Commit aa7b8dd6 authored by Jö Fahlke's avatar Jö Fahlke
Browse files

Fix "warning: assuming signed overflow does not occur when assuming that (X +...

Fix "warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]"

This was a tricky one.  It was highly non-obvious why the compiler even ran
into this issue.  My best guess is as follows: The compiler was trying to
optimize the loop over the vertices in testStaticRefinementGeometry(),
test-refinement.cc:122.  To do this it needed to statically evaluate
vEnd(refinement), where refinement is unsigned, but converted to int due to
the signature of vEnd().  The constructed iterator stores it as unsigned
_level, and it also stores the current position as unsigned _index.  So there
is a conversion from unsigned to int and back to unsigned.

Changing the parameter and return value of vEnd() to unsigned turns out not to
be enough: vEnd calls nVertices(), which also takes and returns an int.
Changing that to unsigned too is still not enough, because nVertices evaluates
the expression Power<dimension>::eval((1<<level)+1).  While level is now
unsigned, the literal 1's are not, and the result of operator<<() will have
the type of the (promoted) left operand (the "usual integral conversions" do
not happen for <<).  Thus we need to change the literals to 1u.

To be clear: the warning happens because of conversion from unsigned to int
and then back to unsigned, where the compiler is unable to fully track all
possible values and cannot prove that everything is fine.

This patch fixes this by making the level parameter unsigned, and by making
sure that any literals are suffixed by u.

Adresses #5.
parent 9e06f119
No related branches found
No related tags found
Loading
Loading
  • Works for me, tested with two Dumux test and all dune-geometry tests using Clang 3.8.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment