[Bug c++/89080] ICE with immediately invoked constexpr lambda

mpolacek at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 28 17:11:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89080

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Which is this.  Curiously, I don't see an ICE with -std=c++2a -fconcepts.

#include <array>


template<auto s>
struct make_7bit{
    static constexpr auto v = s();


    static constexpr unsigned required_bytes = ([](){
        constexpr unsigned bits = (__builtin_strlen(v) * 7);
        constexpr unsigned bits_div = (bits) / 8;
        constexpr unsigned bits_rem = bits % 8;
        return bits_div + (bits_rem ==0 ?0:1);    
    })();

    static constexpr std::array<uint8_t, required_bytes> packed = 
    ([](){
        std::array<uint8_t, required_bytes> packed_data{};

        unsigned currpos = 0;

        auto submit_bit = [&currpos, &packed_data] (unsigned bit){
            packed_data[currpos / 8] |= (bit&1) << (currpos%8);
        };

        auto submit_char = [&submit_bit](char c){
            uint8_t cc = (uint8_t)c;

            for(unsigned i = 0; i < 7;++i){
                submit_bit(cc>>i);
            }
        };

        unsigned l = __builtin_strlen(v);

        for(unsigned i = 0; i < l; ++i){
            submit_char(v[i]);
        }

        return packed_data;
    })();

};

#define static_string(...)  []()constexpr{return __VA_ARGS__;}

using nowdie = make_7bit<static_string("hi")>;

const uint8_t* kills_compiler() {
    return &nowdie::packed[0];
}


More information about the Gcc-bugs mailing list