samedi 27 juillet 2019

constexpr works on Ubuntu, but not MacOS

I have this code which compiles fine on Ubuntu, but when I try to compile it on MacOS I get this error:

Constexpr variable 'HeuristicNames' must be initialized by a constant expression

#define LSHPair std::pair<const char *, LISTSCHED_HEURISTIC>
static constexpr LSHPair HeuristicNames[] = {
    LSHPair("CP", LSH_CP),    LSHPair("LUC", LSH_LUC),
    LSHPair("UC", LSH_UC),    LSHPair("NID", LSH_NID),
    LSHPair("CPR", LSH_CPR),  LSHPair("ISO", LSH_ISO),
    LSHPair("SC", LSH_SC),    LSHPair("LS", LSH_LS),
    LSHPair("LLVM", LSH_LLVM)};

LISTSCHED_HEURISTIC is an enum.

I take this error to mean that some part of the right hand side of the assignment is not a constexpr, so the resulting variable can't be a constexpr. However I don't have a firm enough grasp of the rules around constexpr to understand why, or how to fix it.

I also don't get why this is different on MacOS than on Ubuntu. Can anyone shed some light on this?

Aucun commentaire:

Enregistrer un commentaire