Issue 123052
Summary Call to consteval method from constexpr constructor makes constructor consteval.
Labels new issue
Assignees
Reporter IViktorov
    ```C++
#include <cstdint>
#include <print>


template <class T, std::size_t kSize>
struct Test {
 constexpr Test(const Test& t) noexcept: m_data{t.data()}, m_size{t.size()} {}
    constexpr Test(T (&data)[kSize]) noexcept: m_data{data}, m_size{kSize} {}

    constexpr T* data() const noexcept { return m_data; }
#ifdef NOCONSTEVAL
    constexpr static std::size_t size() noexcept { return kSize; }
#else
    consteval static std::size_t size() noexcept { return kSize; }
#endif

private:
    T* m_data;
    std::size_t m_size;
};



int main() {
    int arr[] = {1, 2, 3, 4, 5, 6};
 Test t1{arr};
    Test t{t1};
    std::println("arr[0] = {}, arr size = {}.", *t.data(), t.size());
}
```

With `consteval size()` method `Test` copy constructor becomes immediate function, but it should not.
Without consteval with `constexpr size()` everything goes as expected.
GCC doesn't have that problem with consteval methods, called in contructors.

https://godbolt.org/z/P157TafW8
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to