Connecting Tech Pros Worldwide Help | Site Map

Re: Unexpected compiler behavior relating to size_t and boost -Visual Studio 2005.

Unknownmat
Guest
 
Posts: n/a
#1: Jul 13 '08
Here is the smallest code I could come up with to reproduce the
Quote:
behavior:
>
#include <vector>
#include <functional>
#include <boost/function.hpp>
>
template< class T >
void test()
{
typedef std::vector< T TItems;
typedef boost::function< bool (T, T) TCompFn;
typedef std::vector< std::size_t TSizes;
>
TItems data;
TCompFn fn = TCompFn( std::greater< T >() );
fn( data.front(), data.front() ); // NOTE: data is empty - will
cause a runtime error if run
>
}
>
int main()
{
test< int >();
test< unsigned >();
>
}
>
I was able to reproduce the warning with an even smaller snippet of
code:

#include <vector>
#include <functional>
#include <boost/function.hpp>

int main()
{
std::vector< std::size_t sizes;
std::vector< unsigned data;

boost::function< bool (unsigned, unsigned) fn = std::greater<
unsigned >();
fn( data.front(), 10 );
}

The warning goes away if I comment out the line "std::vector<
std::size_t sizes;". This behavior baffles me. Any insight would
again be appreciated.

Thanks,
Matt
Christian Hackl
Guest
 
Posts: n/a
#2: Jul 14 '08

re: Re: Unexpected compiler behavior relating to size_t and boost -Visual Studio 2005.


Unknownmat wrote:
Quote:
I was able to reproduce the warning with an even smaller snippet of
code:
>
#include <vector>
#include <functional>
#include <boost/function.hpp>
>
int main()
{
std::vector< std::size_t sizes;
std::vector< unsigned data;
>
boost::function< bool (unsigned, unsigned) fn = std::greater<
unsigned >();
fn( data.front(), 10 );
}
>
The warning goes away if I comment out the line "std::vector<
std::size_t sizes;". This behavior baffles me. Any insight would
again be appreciated.
I cannot reproduce C4267 myself with MSVC 8.0 and Boost 1.35.0, not even
with /Wall. I suggest you try microsoft.public.vc.language (which is the
proper place to ask VC-specific questions, anyway).


--
Christian Hackl
Unknownmat
Guest
 
Posts: n/a
#3: Jul 14 '08

re: Re: Unexpected compiler behavior relating to size_t and boost -Visual Studio 2005.


Thanks for the response - it wasn't clear to me that this was a MSVC
specific bug. Perhaps I shouldn't have added that to the title,
except that I knew it would come up (and rightfully so, apparently).

Curiously, are you using VS 2005 with SP1? I've been able to
reproduce this fairly consistently on multiple computers. I'm a bit
surprised that you say that you cannot reproduce it.

Thanks,
Matt

Christian Hackl wrote:
Quote:
Unknownmat wrote:
>
Quote:
I was able to reproduce the warning with an even smaller snippet of
code:

#include <vector>
#include <functional>
#include <boost/function.hpp>

int main()
{
std::vector< std::size_t sizes;
std::vector< unsigned data;

boost::function< bool (unsigned, unsigned) fn = std::greater<
unsigned >();
fn( data.front(), 10 );
}

The warning goes away if I comment out the line "std::vector<
std::size_t sizes;". This behavior baffles me. Any insight would
again be appreciated.
>
I cannot reproduce C4267 myself with MSVC 8.0 and Boost 1.35.0, not even
with /Wall. I suggest you try microsoft.public.vc.language (which is the
proper place to ask VC-specific questions, anyway).
>
>
--
Christian Hackl
Unknownmat
Guest
 
Posts: n/a
#4: Jul 14 '08

re: Re: Unexpected compiler behavior relating to size_t and boost -Visual Studio 2005.


On Jul 13, 3:42*pm, Unknownmat <unknown...@gmail.comwrote:
Quote:
The warning goes away if I comment out the line "std::vector<
std::size_t sizes;". *This behavior baffles me. *Any insight would
again be appreciated.
>
Thanks,
Matt- Hide quoted text -
>
- Show quoted text -
In case anybody is interested - I figured out what's causing this
issue. Microsoft's "detect 64-bit portability issues" compiler option
causes both false-positives, and false-negatives, and interacts poorly
with templates. This is clearly one of those cases.

Turning off the "/Wp64" switch will eliminate this false warning.

Thanks for the help. Sorry for being OT.

Matt
Closed Thread