Bug 34105 - [4.3 Regression] Confusing error message with missing #include <algorithm>
Summary: [4.3 Regression] Confusing error message with missing #include <algorithm>
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Paolo Carlini
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks:
 
Reported: 2007-11-15 08:57 UTC by Richard Biener
Modified: 2007-11-15 21:54 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-15 11:59:39


Attachments
Draft patch for normal mode (1.69 KB, patch)
2007-11-15 13:04 UTC, Paolo Carlini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2007-11-15 08:57:43 UTC
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?
Comment 1 Paolo Carlini 2007-11-15 11:59:38 UTC
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.
Comment 2 Paolo Carlini 2007-11-15 13:04:42 UTC
Created attachment 14555 [details]
Draft patch for normal mode
Comment 3 Paolo Carlini 2007-11-15 13:06:26 UTC
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...
Comment 4 Paolo Carlini 2007-11-15 13:09:37 UTC
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.
Comment 5 Paolo Carlini 2007-11-15 13:10:14 UTC
I meant bits/stl_algobase.h, of course.
Comment 6 Paolo Carlini 2007-11-15 18:14:56 UTC
I'm finishing testing a complete patch.
Comment 7 paolo@gcc.gnu.org 2007-11-15 19:05:32 UTC
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

Comment 8 Paolo Carlini 2007-11-15 19:07:28 UTC
Fixed.
Comment 9 Benjamin Kosnik 2007-11-15 21:54:48 UTC
Awesome. Looks good. 

Comment 10 rguenther@suse.de 2007-11-16 09:45:00 UTC
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.