Re: Incorrect compiler warning C4267



Number 774 wrote:
I'm running VS 2005, configured for 32 bit with 64 bit warnings on. This
bit of code

#include <vector>
#include <list>
std::vector<size_t> vs;
std::list<unsigned int> uiList;
unsigned int ui = uiList.front();

results in a compiler warning at the last line
warning C4267: 'initializing' : conversion from 'size_t' to 'unsigned
int', possible loss of data uiList.front()'s data type should be
reference to unsigned int, so it ought to compile fine.

Following problem: size_t and unsigned int are the same types as far as C++
is concerned. MS' compiler attaches to the size_t typedef the additional
information that it might be 64 bits, which it doesn't attach to unsigned
int (I'm just starting to wonder why size_t isn't unsigned long
instead...?). Now, vector<size_t> instantiates other types like e.g.
allocator<size_t> which is identical to allocator<unsigned int>. When using
the same allocator as allocator<unsigned int> the compiler uses
allocator<size_t> with the additional info that it might be 64 bits still
attached, ergo your bogus compiler warning.

Disclaimer: I'm only guessing how the compiler works, I don't have the
sources at hand to check.

I reckon this is a compiler bug.

Yep, though it isn't likely to cause any severe misbehaviour.

Uli

.



Relevant Pages

  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Re: [CodeGallery] MFC MD5 Calculator
    ... Then when they added types, internally, the compiler still thought they were int values, ... ANSI standard began to emerge that the language design ...
    (microsoft.public.vc.mfc)
  • Re: cpu type idea
    ... compiler related recently. ... int main ... float a; ... just to parallelize the vectror and tensor operations. ...
    (alt.lang.asm)