This is an archive of the discontinued LLVM Phabricator instance.

Make __wrap_iter work with gcc
ClosedPublic

Authored by thakis on Jan 27 2015, 9:54 AM.

Details

Summary

The following snippet doesn't build when using gcc and libc++:

#include <string>
void f(const std::string& s) { s.begin(); }
#include <vector>
void AppendTo(const std::vector<char>& v) { v.begin(); }

The problem is that wrap_iter has a private constructor. It lists vector<> and basic_string<> as friends, but gcc seems to ignore this for vector<> for some reason. Declaring vector before the friend declaration in wrap_iter is enough to work around this problem, so do that. With this patch, I'm able to build chromium/android with libc++. Without it, two translation units fail to build.

As far as I can tell, this is due to a gcc bug, which I filed as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64816.

Fixes PR22355.

Diff Detail

Event Timeline

thakis updated this revision to Diff 18822.Jan 27 2015, 9:54 AM
thakis retitled this revision from to Make __wrap_iter work with gcc.
thakis updated this object.
thakis edited the test plan for this revision. (Show Details)
thakis added a reviewer: danalbert.
thakis added a subscriber: Unknown Object (MLST).
mclow.lists added inline comments.
include/iterator
1116

There's also a friend decl for basic_string in __wrap_iter; why don't we need a fwd declaration for that as well?

(because it's a compiler bug?)

thakis added inline comments.Jan 27 2015, 10:30 AM
include/iterator
1116

I wondered about this too, but I wasn't able to tickle the symmetric problem for string. I think it's because iterator includes iosfwd, and iosfwd declares basic_string (as that file is where typedef basic_string<char> string lives, for some reason).

thakis added inline comments.Jan 27 2015, 10:38 AM
include/iterator
1116

In other words, there already is a forward declaration of basic_string somewhere.

thakis updated this revision to Diff 18832.Jan 27 2015, 11:20 AM

Add _LIBCPP_TYPE_VIS_ONLY to forward decl.

mclow.lists accepted this revision.Jan 27 2015, 11:21 AM
mclow.lists added a reviewer: mclow.lists.

LGTM.

This revision is now accepted and ready to land.Jan 27 2015, 11:21 AM
thakis closed this revision.Jan 27 2015, 11:29 AM

t227226, thanks!