http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60420

            Bug ID: 60420
           Summary: [C++11] Bogus "error: ‘const’ qualifiers cannot be
                    applied to ‘int&’" with lambda
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppluzhnikov at google dot com

Google ref: b/13305941

Using current (r208339) trunk:

g++ -c -std=c++11 t.cc
t.cc: In instantiation of ‘struct fn(Iterator, Iterator) [with Iterator =
__gnu_cxx::__normal_iterator<int*, std::vector<int> >]::<lambda>’:
t.cc:6:45:   required from ‘void fn(Iterator, Iterator) [with Iterator =
__gnu_cxx::__normal_iterator<int*, std::vector<int> >]’
t.cc:11:26:   required from here
t.cc:6:38: error: ‘const’ qualifiers cannot be applied to ‘int&’
   auto x = [](const decltype(*begin) b) { };
                                      ^
t.cc: In instantiation of ‘struct fn(Iterator, Iterator) [with Iterator =
__gnu_cxx::__normal_iterator<const int*, std::vector<int> >]::<lambda>’:
t.cc:6:45:   required from ‘void fn(Iterator, Iterator) [with Iterator =
__gnu_cxx::__normal_iterator<const int*, std::vector<int> >]’
t.cc:16:26:   required from here
t.cc:6:38: error: ‘const’ qualifiers cannot be applied to ‘const int&’

Clang accepts this test case. GCC-4.8 gives up with "confused by earlier
errors, bailing out" after the first error.



#include <vector>

template <typename Iterator>
void fn(Iterator begin, Iterator end)
{
  auto x = [](const decltype(*begin) b) { };
}

void foo(std::vector<int> &vi)
{
  fn(vi.begin(), vi.end());
}

void bar(const std::vector<int>& vi)
{
  fn(vi.begin(), vi.end());
}

Reply via email to