Подтвердить что ты не робот

Возможная std:: forward регрессия с g++ 6.1 - ошибка или предполагаемое поведение?

g++ 6.1 был недавно введен в репозитории тестирования Arch Linux, и некоторые из моего кода, который успешно скомпилирован с g++ 5.3.0, больше не компилируются. Я сделал минимальный пример:

ссылка gcc.godbolt.org

// This code compiles with g++ 5.3.0
// This does not compile with g++ 6.1

#include <type_traits>
#include <utility>
#include <tuple>

#define FWD(...) ::std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)

struct sinker
{
    template <typename T>
    void sink(T&)
    {
    }
};

template <typename T, typename TF>
void caller(T& v, TF&& f)
{
    sinker s;
    f(s, v);
}

template <typename T>
void interface(T& v)
{
    return caller(v, [](auto& xs, auto&& xv) -> decltype(auto)
        {
            xs.sink(FWD(xv));
        });
}

int main()
{
    int x = 0;
    interface(x);
}

Это ошибка:

: In instantiation of ‘get_impl(T&)::<lambda(auto:1&, auto:2&&)> [with auto:1 = sinker; auto:2 = int; T = int]’:
:25:58:   required by substitution of ‘template<class auto:1, class auto:2> get_impl(T&)
      [with T = int]::<lambda(auto:1&, auto:2&&)>::operator 
      decltype (((get_impl(T&) [with T = int]::<lambda(auto:1&, auto:2&&)>)0u).operator()(static_cast<auto:1&>(<anonymous>),
       static_cast<auto:2&&>(<anonymous>))) (*)(auto:1&, auto:2&&)() const [with auto:1 = sinker; auto:2 = int]’
:19:6:   required from ‘void chunk_fn_impl(T&, TF&&) [with T = int; TF = get_impl(T&) [with T = int]::<lambda(auto:1&, auto:2&&)>]’
:25:25:   required from ‘void get_impl(T&) [with T = int]’
:36:15:   required from here
:27:13: error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
             xs.sink(FWD(md));
             ^~
:10:10: note:   initializing argument 1 of ‘void sinker::sink(T&) [with T = int]’
     void sink(T&)
          ^~~~

Изменение:

return caller(v, [](auto& xs, auto&& xv) -> decltype(auto)

в

return caller(v, [](auto& xs, auto& xv) -> decltype(auto)

позволяет успешно компилировать код.


Я не понимаю, почему эта ошибка происходит, поскольку xv отлично переадресуется, а вызов FWD(xv) должен давать ссылку lvalue. Обратите внимание, что код работал так, как предполагалось, в g++ 5.3.0 и clang++ 3.7.

ссылка gcc.godbolt.org

(Попробуйте выполнить компиляцию с несколькими версиями g++ и сменив auto&& на auto&.)

Является ли это ошибкой g++ 6.1? Или код некорректно компилировался с предыдущими версиями g++ и clang++?

4b9b3361

Ответ 1

Это ошибка интерфейса g++: проблема была отмечена как ошибка 70942.