C++ 98.  But those might be acceptable limitations (at least
in C there's a workaround).

__builtin_* is an extension.  Perhaps for C (any) and C++ (< C++14)
you could require that in constant expressions the last argument
of the builtin has to be a NULL pointer cast to some pointer type
(not necessarily a constant expression)?  This can be handled
simply by saving/restoring the constant expression context around
the parsing of the last argument of the builtin, and afterwards
verifying it has the required properties.

I'll see if there's an easy way to make it work.


For C++14 and later, it would be nice if one could also do:
struct S { int val; bool ovf; };
constexpr S foo (int x, int y)
{
   S ret = { 0, false };
   ret.ovf = __builtin_add_overflow (x, y, &ret.val);
   return ret;
}
instead of doing:
   ret.ovf = __builtin_add_overflow (x, y, (int *) 0);
   ret.val = (unsigned) x + y;
or similar.
Does that work with your patch?

Yes, it does (it's exercised by the constexpr-arith-overflow.C
test).  The patch is in part motivated by GCC needing to make
use of the overflow built-ins in constexpr functions (to detect
VLA bounds overflow).

Martin

Reply via email to