I was merily experimenting with the new trailing return types, where I hit a problem with this (simplified) code

#include <list>

class MyContainer{
  std::list<int> ints;

  auto begin( ) -> decltype(ints.begin())
  {
    return ints.begin();
  }

  auto begin( ) const -> decltype(ints.begin())
  {
    return ints.begin();
  }
};

Ignore the fact of how pointless this code is. The important part is the compiler error generated when using GCC 4.6.1 (with -std=c++0x flag):

In member function 'std::list<int>::iterator MyContainer::begin() const':
error: could not convert '((const MyContainer*)this)->MyContainer::ints.std::list<_Tp, _Alloc>::begin [with _Tp = int, _Alloc = std::allocator<int>, std::list<_Tp, _Alloc>::const_iterator = std::_List_const_iterator<int>]()' from 'std::list<int>::const_iterator {aka std::_List_const_iterator<int>}' to 'std::list<int>::iterator {aka std::_List_iterator<int>}'

In case you're not of fan of error involving templates, the short story is that in the body of the const version of MyContainer::begin, the expression ints.begin() returns a value of type std::list<int>::const_iterator (since ints is const in such a context). However, decltype(ints.begin()) produces the type std::list<int>::iterator, i.e. decltype ignores the const qualifier of the begin method when deciding the type of the expression. Unsurprisingly, a conflict in types is the result.

This seems to me to be a bug in the GCC compiler. It would only make sense for decltype to honor the const qualifier and produce the const_iterator type. Can anyone confirm or deny (maybe even explain) this? Maybe I am overlooki

Edit
Report