Minor bug gets bigger? (was Re: Potential minor bu revealed?)

Phil Edwards phil@jaj.com
Wed May 8 11:17:00 GMT 2002


On Tue, May 07, 2002 at 03:26:38PM -0400, Stephen M. Webb wrote:
> stephen_[176]>  g++ -o br br.cc
> br.cc: In function `int main(int, char**)':
> br.cc:9: conversion from `int' to non-scalar type `std::_Bit_reference' 
>     requested
> 
> This message is a little confusing to say the least.  I get a more 
> relevant message if I remove the <iostream> inclusion.

What version are you using?  The _Bit_reference class is in stl_bvector.h,
which doesn't get included with only <algorithm> and <iostream>.  Using the
current 3.1 prerelease, I get this error instead:

> stephen_[177]> g++ -o br1 br1.cc
> br1.cc: In function `int main(int, char**)':
> br1.cc:8: no matching function for call to `swap(int&, const int&)'

Now, if I also include <vector>, then the weird error appears.  This makes
sense to me and my limited understanding of template function overloading:
the compiler never instantiates the template form of std::swap, since it
already sees a non-template function.  Which unfortunately happens to be
for a class which nobody would ever use.

Changing your test case to specifically use the template version gives
various const-related errors, as desired.


> Other than the confusing error message, would this indicate a potential 
> problem in vector<bool>?

Well, it wouldn't be the first problem with vector<bool>...  anyhow,
I note that the standard doesn't specify a non-template std::swap() for
vector's "bit reference" class.  But we have one.  The standard /does/
specify a static non-template member function, std::vector::swap, for the
bit reference class, but we /don't/ have one.

Moving the _Bit_reference's swap down inside the vector<bool> specialization,
like the standard says, makes this problem go away.  I'll post a patch
after 3.1 is out.


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



More information about the Libstdc++ mailing list