Skip to content

Clang fails to compile consteval because of conflicting rule for variable arrays (?) #105796

@socketpair

Description

@socketpair

https://godbolt.org/z/dKE6sa4PW

#include <algorithm>
#include <array>

template <std::size_t N>
struct CompTimeStr {
    std::array<char, N> store;

    consteval CompTimeStr(const char (&str)[N]) {
        std::copy_n(str, store.size(), store.data());
    }

    template <std::size_t N2>
    consteval CompTimeStr<N + N2 - 1> operator+(
        const CompTimeStr<N2> str) const {
        char newchar[size() + str.size() + 1];
        std::copy_n(data(), size(), newchar);
        std::copy_n(str.data(), str.size() + 1, newchar + size());
        return newchar;
    }

    consteval std::size_t size() const { return store.size() - 1; }
    consteval const char* data() const { return store.data(); }
};

template <CompTimeStr str>
consteval auto addBar() {
    return str + str;
}

int main() {
    constexpr CompTimeStr str = addBar<"foo">();

    return str.size();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyconstevalC++20 constevaldiverges-from:gccDoes the clang frontend diverge from gcc on this issueextension:gnu

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions