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

--- Comment #2 from eric-bugs at omnifarious dot org ---
Also, this works in clang 6.0 (with --std=c++17), but not gcc 8.2:

--------
#include <array>

constexpr int ce_strlen(char const *s)
{
    int i = 0;
    while (s[i]) ++i;
    return i;
}

template <int len>
constexpr auto as_array(char const *s)
{
    ::std::array<char, len + 1> output{};
    for (int i = 0; i < len; ++i) {
        output[i] = s[i];
    }
    output[output.size() - 1] = '\0';
    return output;
}

template <unsigned long s1, unsigned long s2>
constexpr auto paste_array(::std::array<char, s1> a, ::std::array<char, s2> b)
{
    constexpr unsigned long tlen = s1 + s2 - 1;
    ::std::array<char, tlen> output{};
    int o = 0;
    for (unsigned long i = 0; i < s1; ++i, ++o) {
        output[o] = a[i];
    }
    --o;
    for (unsigned long i = 0; i < s2; ++i, ++o) {
        output[o] = b[i];
    }
    return output;
}

#define stringify(x) #x
#define evstringify(x) stringify(x)

char const * joe()
{
    constexpr static auto mystr =
paste_array(paste_array(as_array<ce_strlen(__PRETTY_FUNCTION__)>(__PRETTY_FUNCTION__),
as_array<sizeof(" at line ") - 1>(" at line ")),
as_array<ce_strlen(evstringify(__LINE__))>(evstringify(__LINE__)));
    return mystr.data();
}

Reply via email to