ibex-team / ibex-lib

IBEX is a C++ library for constraint processing over real numbers.
http://ibex-team.github.io/ibex-lib/
GNU Lesser General Public License v3.0
69 stars 51 forks source link

Undefined behavior in ExprNode::accept_visitor could lead to unexpected behavior #485

Closed cyrilbouvier closed 3 years ago

cyrilbouvier commented 3 years ago

As pointed by the compiler, the method ExprNode::accept_visitor must return a value, but, in some cases, do not. For example, if the 'default' case is reached and asserts are disabled (they are disabled by CMake and waf if not in debug compile mode).

From https://en.cppreference.com/w/cpp/language/return:

Flowing off the end of a value-returning function (except main) without a return statement is undefined behavior.

Undefined behavior are dangerous, because, even if the problematic portion of the code cannot be reached and is never reached, the compiler may do whatever it wants with it (like compiling the function to an empty function), see https://en.cppreference.com/w/cpp/language/ub.

gchabert commented 3 years ago

Cyril OK; I'll do the changes. I guess returning dummy values is enough (as error 'default' cases should not be reachable). Surprisingly, I never saw these warnings. Did you compile ibex in a specific way?

cyrilbouvier commented 3 years ago

I am compiling with gcc 8.3 and flags -O3 -DNDEBUG.

gchabert commented 3 years ago

I think it is ok now, can you confirm and close the ticket?

cyrilbouvier commented 3 years ago

I confirm that the warning is gone and there is no more undefined behavior.