Skip to content

Clang fails to compile correct program with consteval #105558

@socketpair

Description

@socketpair

https://godbolt.org/z/3o1G81ahn

#include <array>
#include <iostream>
#include <ranges>
#include <string>

using namespace std;

template <size_t N>
consteval auto make_static(const string& str) {
    array<char, N> arr;
    str.copy(arr.data(), arr.size());
    return arr;
}

consteval string foo() { return string("some dynamic data") + " 42\n"; }

int main() {

// WORKS:
//    constexpr auto xxx = make_static<foo().size()>(foo());
//    cout << (xxx | ranges::to<string>());

   cout << (make_static<foo().size()>(foo()) | ranges::to<string>());

    return 0;
}

Clang fails to compile correct (I think yes :) program. GCC works. UB ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyconstevalC++20 consteval

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions