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

--- Comment #1 from milasudril at gmail dot com ---
For reference, here is a MWE:

#include <cstddef>
#include <array>

template<class SourceArray, class TargetArray>
struct CreateArray
    {
    using value_type = typename TargetArray::value_type;

    auto operator()()
        {
        TargetArray ret;
        for(int k = 0 ; k < std::size(src) - 1; ++k)
            {ret[k] = value_type{src[k]};}
        return ret;
        }

    SourceArray const& src;
    };

class TestA
    {
    public:
        using value_type = char;

        static constexpr size_t npos = 255;
        template<class SrcType, size_t N>
        TestA(SrcType const (&src)[N]
            , std::enable_if_t<(N>=1 && N<npos &&
sizeof(SrcType)<=sizeof(value_type)), int> x = 0)
            : m_size{N - 1}
            , m_data{CreateArray<decltype(src), decltype(m_data)>{src}()}
            {}
    private:
        size_t m_size;
        std::array<value_type, npos> m_data;
    };

class TestB
    {
    public:
        using value_type = char;

        static constexpr size_t npos = 255;
        template<class SrcType, size_t N>
        TestB(SrcType const (&src)[N]
            , std::enable_if_t<(N>=1 && N<npos &&
sizeof(SrcType)<=sizeof(value_type)), int> x = 0)
            : m_size{N - 1}
            , m_data
                {
                [&src]()
                    {
                    std::array<value_type, npos> ret;
                    for(int k = 0 ; k < std::size(src) - 1; ++k)
                        {ret[k] = value_type{src[k]};}
                    return ret;
                    }()
                }
            {}
    private:
        size_t m_size;
        std::array<value_type, npos> m_data;
    };

TestB hello_2()
    {return TestB{"Hello, World! This is a very long string that the compiler
probably will not inline"};}

TestA hello_1()
    {return TestA{"Hello, World! This is a very long string that the compiler
probably will not inline"};}

Reply via email to