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

            Bug ID: 77337
           Summary: [7 regression][c++1z] use before deduction of 'auto'
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lucdanton at free dot fr
  Target Milestone: ---

The included program compiles on 6.1 and I think on the 6.2 branch (I would
need definite confirmation however), with either -std=c++14 or -std=c++1z.

On 7 trunk (rev. 239676) it compiles as well with the following:
$ g++-trunk -std=c++14 main.cpp

but it fails in c++1z mode:
$ g++-trunk -std=c++1z main.cpp                      
main.cpp: In instantiation of 'main()::<lambda(auto:1&)> [with auto:1 =
fix_type<main()::<lambda(auto:1&)> >]':
main.cpp:6:27:   required from 'decltype(auto) fix_type<Functor>::operator()()
[with Functor = main()::<lambda(auto:1&)>]'
main.cpp:25:17:   required from here
main.cpp:21:17: error: use of 'decltype(auto) fix_type<Functor>::operator()()
[with Functor = main()::<lambda(auto:1&)>]' before deduction of 'auto'
             self();
             ~~~~^~

I'm not 100% sure that GCC should accept the program though. FWIW Clang accepts
it.

//------------------

template<typename Functor>
struct fix_type {
    Functor functor;

    decltype(auto) operator()()
    { return functor(*this); }
};

template<typename Functor>
fix_type<Functor> fix(Functor functor)
{ return { functor }; }

int main()
{
    auto zero = fix(
        [](auto& self) -> int // N.B. non-deduced, non-dependent return type
        {
            return 0;

            // error: use of 'decltype(auto) fix_type<Functor>::operator()()
[with Functor = main()::<lambda(auto:1&)>]' before deduction of 'auto'
            self();
        }
    );

    return zero();
}

Reply via email to