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

            Bug ID: 113809
           Summary: Error of constexpr variable creation due to combined
                    use of std::tuple, copy constructor and static
                    function
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bobk-off at yandex dot ru
  Target Milestone: ---

Compiler reports following error on code below:

in 'constexpr' expansion of 'A<int>(MakeFullPGNsMap::value)'
in 'constexpr' expansion of
'((A<int>*)this)->A<int>::A<0>(other.A<int>::mTuple,
(std::make_index_sequence<1>(), std::make_index_sequence<1>()))'
error: the value of 'MakeFullPGNsMap::value' is not usable in a constant
expression


Note: code is strognly reduced to only demonstrate compilation error.

Code: 

#include <algorithm>
#include <tuple>

template<typename T, typename ... TARGS>
struct ConstantObject { static constexpr T value = { TARGS::value... }; };

template<typename ... Ts>
struct A {

        A & operator =(const A & other) = delete;

        constexpr A(const std::tuple<Ts...> & tuple) : A(tuple,
std::make_index_sequence<sizeof...(Ts)>()) {}
        constexpr A(const A & other) : A(other.mTuple,
std::make_index_sequence<sizeof...(Ts)>()) {}

private:
        template<size_t ... Is>
        constexpr A(const std::tuple<Ts...> & tuple,
std::index_sequence<Is...>) : mTuple(tuple), mMap{ &std::get<Is>(mTuple)... }
{}

        std::tuple<Ts...> mTuple;
        const void * mMap[sizeof...(Ts)] = {};
};

template<typename ... Ts>
static constexpr A<Ts...> make_a(const std::tuple<Ts...> & spns) {
        return A<Ts...>(spns);
}

struct MakeFullPGNsMap {;
    static constexpr A<int> value = make_a(std::make_tuple(5));
};

using X = ConstantObject<decltype(MakeFullPGNsMap::value), MakeFullPGNsMap>;

const void * y;

int main() {
    y = &X::value;
    return 0;
}

Reply via email to