public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eltoder at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/53339] New: unordered_map::iterator requires Value to be complete type
Date: Sun, 13 May 2012 22:23:00 -0000	[thread overview]
Message-ID: <bug-53339-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 53339
           Summary: unordered_map::iterator requires Value to be complete
                    type
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eltoder@gmail.com


Created attachment 27393
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27393
Simple test case

Sometimes it's useful to refer to map's iterator from map's value, e.g.:

#include <string>
#include <tr1/unordered_map>

struct LinkedHashMap
{
    struct Entry;
    typedef std::tr1::unordered_map<std::string, Entry> Storage;
    typedef Storage::iterator EntryPtr; // <-- fails here
    struct Entry
    {
        EntryPtr prev, next;
    };

    Storage  storage_;
    EntryPtr head_;
};

(here we combine hash map with linked list implemented via iterators).
It doesn't seem unreasonable to expect this to compile, however it doesn't:

In file included from /usr/include/c++/4.6/bits/stl_algobase.h:65:0,
                 from /usr/include/c++/4.6/bits/char_traits.h:41,
                 from /usr/include/c++/4.6/string:42,
                 from linkedhash.cc:1:
/usr/include/c++/4.6/bits/stl_pair.h: In instantiation of 'std::pair<const
std::basic_string<char>, LinkedHashMap::Entry>':
/usr/include/c++/4.6/bits/stl_function.h:486:12:   instantiated from
'std::_Select1st<std::pair<const std::basic_string<char>, LinkedHashMap::Entry>
>'
/usr/include/c++/4.6/tr1/hashtable_policy.h:708:20:   instantiated from
'std::tr1::__detail::_Hash_code_base<std::basic_string<char>, std::pair<const
std::basic_string<char>, LinkedHashMap::Entry>, std::_Select1st<std::pair<const
std::basic_string<char>, LinkedHashMap::Entry> >,
std::equal_to<std::basic_string<char> >, std::tr1::hash<std::basic_string<char>
>, std::tr1::__detail::_Mod_range_hashing,
std::tr1::__detail::_Default_ranged_hash, false>'
/usr/include/c++/4.6/tr1/hashtable.h:108:11:   instantiated from
'std::tr1::_Hashtable<std::basic_string<char>, std::pair<const
std::basic_string<char>, LinkedHashMap::Entry>, std::allocator<std::pair<const
std::basic_string<char>, LinkedHashMap::Entry> >,
std::_Select1st<std::pair<const std::basic_string<char>, LinkedHashMap::Entry>
>, std::equal_to<std::basic_string<char> >,
std::tr1::hash<std::basic_string<char> >,
std::tr1::__detail::_Mod_range_hashing,
std::tr1::__detail::_Default_ranged_hash,
std::tr1::__detail::_Prime_rehash_policy, false, false, true>'
/usr/include/c++/4.6/tr1/unordered_map.h:43:11:   instantiated from
'std::tr1::__unordered_map<std::basic_string<char>, LinkedHashMap::Entry,
std::tr1::hash<std::basic_string<char> >, std::equal_to<std::basic_string<char>
>, std::allocator<std::pair<const std::basic_string<char>,
LinkedHashMap::Entry> >, false>'
/usr/include/c++/4.6/tr1/unordered_map.h:180:11:   instantiated from
'std::tr1::unordered_map<std::basic_string<char>, LinkedHashMap::Entry>'
linkedhash.cc:8:20:   instantiated from here
/usr/include/c++/4.6/bits/stl_pair.h:93:11: error: 'std::pair<_T1,
_T2>::second' has incomplete type
linkedhash.cc:6:12: error: forward declaration of 'struct LinkedHashMap::Entry'

The problem is that _Select1st<pair<Key,Value> > forces instantiation of pair
when trying to declare its return type:

template<typename _Pair>
struct _Select1st : public unary_function<_Pair,
                                          typename _Pair::first_type> // <--

but pair cannot be instantiated until both types are complete. This is can be
worked around by using unordered_set or using _Hashtable directly, but
* This code compiles if unordered_map is replaced by map. Would be nice to keep
them consistent.
* There doesn't seem to be any fundamental reason why this doesn't work -- it
comes from a minor implementation choice and seems very easy to fix.


             reply	other threads:[~2012-05-13 22:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-13 22:23 eltoder at gmail dot com [this message]
2012-05-13 22:27 ` [Bug libstdc++/53339] " eltoder at gmail dot com
2012-05-14  2:12 ` redi at gcc dot gnu.org
2012-05-14  2:40 ` paolo.carlini at oracle dot com
2012-05-14  3:20 ` eltoder at gmail dot com
2012-05-14  5:06 ` eltoder at gmail dot com
2012-05-14  5:29 ` eltoder at gmail dot com
2012-05-14 10:54 ` paolo.carlini at oracle dot com
2012-05-14 11:15 ` paolo.carlini at oracle dot com
2012-05-14 13:14 ` paolo.carlini at oracle dot com
2012-05-14 13:29 ` paolo.carlini at oracle dot com
2012-05-15  1:11 ` paolo.carlini at oracle dot com
2012-05-15  2:09 ` eltoder at gmail dot com
2012-05-15  4:25 ` eltoder at gmail dot com
2012-05-15  9:29 ` paolo.carlini at oracle dot com
2012-05-15 10:07 ` paolo at gcc dot gnu.org
2012-05-15 10:11 ` paolo.carlini at oracle dot com
2012-05-15 12:40 ` eltoder at gmail dot com
2012-05-15 13:16 ` paolo.carlini at oracle dot com
2012-05-16  2:14 ` redi at gcc dot gnu.org
2012-05-16  2:52 ` eltoder at gmail dot com
2012-05-16  3:04 ` redi at gcc dot gnu.org
2012-05-16  9:34 ` paolo.carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53339-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).