For #include <vector> #include <string> int main() { std::vector<std::string> x; std::string s("hello"); return std::find(x.begin(), x.end(), s) - x.begin(); } we now get "interesting" linker errors with trunk: > g++-4.3 -o t t.C /tmp/cc3Vq2t8.o: In function `main': t.C:(.text+0x65): undefined reference to `__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > std::find<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' collect2: ld returned 1 exit status where it is not exactly obvious that just the #include <algorithm> is missing here. With 4.2 and 4.2 at least the program linked fine (I guess algorithm was pulled in anyway). Can we improve this situation by not making algorithm half-way available so we can raise a meaningful error instead?
Note that the issue is unrelated to the header optimization work: is caused by algorithmfwd.h, added in the occasion of the parallel STL work. I'm going to look a bit into it, anyway, if a simple solution I have in mind will not work, will forward to Benjamin.
Created attachment 14555 [details] Draft patch for normal mode
Something like the attached (lightly tested) fixed the problem for normal mode, the error becomes: 34105.cc: In function ‘int main()’: 34105.cc:8: error: ‘find’ is not a member of ‘std’ however, it doesn't for parallel mode. I think it's better if Benjamin looks into those headers...
By the way, while we are talking about those QoI issues, I think it's in any case better not including something like algorithmfwd.h in algobase.h: it's relatively big and we are doing our best to keep algobase.h, the core algorithmic facilities optimized for internal use, as minimal as possible.
I meant bits/stl_algobase.h, of course.
I'm finishing testing a complete patch.
Subject: Bug 34105 Author: paolo Date: Thu Nov 15 19:05:17 2007 New Revision: 130207 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130207 Log: 2007-11-15 Paolo Carlini <pcarlini@suse.de> PR libstdc++/34105 * include/bits/stl_algobase.h: Do not include <bits/algorithmfwd.h>. (lexicographical_compare(const unsigned char*, const unsigned char*, const unsigned char*, const unsigned char*), lexicographical_compare(const char*, const char*, const char*, const char*)): Move to namespace (std, _GLIBCXX_STD_P). * include/parallel/algobase.h: Do not include <bits/algorithmfwd.h>. (equal): Move after mismatch. * include/bits/stl_heap.h (is_heap, is_heap_until): Reorder. * include/bits/char_traits.h: Include <bits/stl_algobase.h> instead of <bits/algorithmfwd.h>. * include/bits/stl_algo.h: Include first <bits/algorithmfwd.h>. * include/bits/algorithmfwd.h (lexicographical_compare): Do not declare overloads. * include/parallel/partition.h: Include <parallel/random_number.h>. * testsuite/util/testsuite_abi.cc: Include <algorithm>. Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/algorithmfwd.h trunk/libstdc++-v3/include/bits/char_traits.h trunk/libstdc++-v3/include/bits/stl_algo.h trunk/libstdc++-v3/include/bits/stl_algobase.h trunk/libstdc++-v3/include/bits/stl_heap.h trunk/libstdc++-v3/include/parallel/algobase.h trunk/libstdc++-v3/include/parallel/partition.h trunk/libstdc++-v3/testsuite/util/testsuite_abi.cc
Fixed.
Awesome. Looks good.
Subject: Re: [4.3 Regression] Confusing error message with missing #include <algorithm> On Thu, 15 Nov 2007, pcarlini at suse dot de wrote: > ------- Comment #8 from pcarlini at suse dot de 2007-11-15 19:07 ------- > Fixed. Thanks Paolo! Richard.