$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-10-19 23:58:40
David Abrahams wrote:
> Vladimir Prus wrote:
> 
>> Hi,
>> I've just updated my copy of boost-sandbox and start to get the following
>> error from g++ 3.3:
>    ^^^^^
> That's a warning, not an error.
True, I've made a typo.
>> /space/NM/boost-sandbox/boost/sequence_algo/container_algo.hpp: In
>> function `
>>    typename boost::container_traits<Container>::const_iterator
>>    boost::find(const Container&, const T&) [with Container =
>>    std::vector<int, std::allocator<int> >, T = int]':
>> .../../lib/lvk/program_analysis/dataflow.cpp:145:   instantiated from
>> here /space/NM/boost-sandbox/boost/sequence_algo/container_algo.hpp:150:
>> warning: cannot
>>    pass objects of non-POD type `struct
>>    boost::contiguous_sequence_container_tag' through `...'; call will
>>    abort at runtime
>> 
>> When I compile the container_algo.cpp test program it produces lots of
>> similiar warnings, after which I get:
>> 
>> bash-2.05b$ ./a.out
>> Segmentation fault
>> 
>> Seems like the warning is correct in predicting crash?
> 
> No, the function is never called.
Are you 100% sure? When running the test program I get:
(gdb) b container_algo.hpp:127
Breakpoint 2 at 0x8065c45: file container_algo.hpp, line 127.
(gdb) b container_algo.hpp:134
Breakpoint 3 at 0x8065d8f: file container_algo.hpp, line 134.
(gdb) c
Continuing.
Breakpoint 2, find_impl<std::pair<int*, int*>, int> (c=@0xbffff740,
value=@0xbffff6dc)
    at container_algo.hpp:127
127             return std::find( begin( c ), end( c ), value );
(gdb) list
122
123         template< typename C, typename T >
124         inline typename container_traits<C>::iterator
125         find_impl( C& c, const T& value, ... )
126         {
127             return std::find( begin( c ), end( c ), value );
128         }
That's one of the function about which gcc warns. 
>> I suggest that instead of using "tag" types for determining the right
>> function to call, the pointer to "tag" is used. I.e. for one fragment one
>> would get:
>> 
>>     template< typename C, typename T >
>>     inline typename container_traits<C>::iterator
>>     find_impl( C& c, const T& value, associative_container_tag* ) ...
>> 
>>     template< typename C, typename T >
>>     inline typename container_traits<C>::iterator
>>     find_impl( C& c, const T& value, ... ) .....
> 
> I don't know if that change is applicable in this case, but in general
> it is not, since the type to be passed may be a reference type.
For this case, I believe it's applicable, since container tag is never
reference. As for general case: well, "is_convertible.hpp" has a lot of
code to handle this in a general way for all the compilers out there, and
that code is complex. Using pointer type is simpler for container_traits.
- Volodya