sipa / minisketch

Minisketch: an optimized library for BCH-based set reconciliation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strict c++11 std::initializer_list constexpr error

theuni opened this issue · comments

For some crazy reason, std::initializer_list::begin() is not constexpr in c++11. Though libstdc++ doesn't care, libc++ does. Building as c++14 works fine.

Before I try to learn the code and hack something together, maybe @sipa sees an easy fix?

fields/generic_1byte.cpp:22:22: error: constexpr variable 'SQR_TABLE_2' must be initialized by a constant expression
constexpr StatTable2 SQR_TABLE_2{0x1, 0x3};
^~~~~~~~~~~~~~~~~~~~~
fields/../lintrans.h:115:72: note: non-constexpr function 'begin' cannot be used in a constant expression
constexpr RecLinTrans(std::initializer_list init) : RecLinTrans(init.begin(), Num()) {}
^
fields/generic_1byte.cpp:22:22: note: in call to 'RecLinTrans({&{1, 3}[0], 2})'
constexpr StatTable2 SQR_TABLE_2{0x1, 0x3};
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/initializer_list:89:16: note: declared here
const _Ep* begin() const _NOEXCEPT {return _begin;}
^
fields/generic_1byte.cpp:23:22: error: constexpr variable 'QRT_TABLE_2' must be initialized by a constant expression
constexpr StatTable2 QRT_TABLE_2{0x2, 0};
...
...

@theuni Is .data() constexpr?

@sipa Afaik there is no .data().

I think this could maybe be made to work by accepting a std::array<I,BITS>&& in ctors, and storing it as a std::array rather than a bare one.

Ah, that would be great if it works.

@theuni See #6. I can't get it to work with std::array, but plain old arrays do seem to work.