jeudi 17 juin 2021

static_assert throws error 'non-constant condition for static assertion'

Why is this code a non-constant condition?

static_assert(4294965 * 1000 / 1000 == -2, "overflow occurs");

But this is not:

const int overflowed = 4294965 * 1000 / 1000;
static_assert(overflowed == -2, "overflow occurs");

See code on godbolt.

Aucun commentaire:

Enregistrer un commentaire