Why does this compile?

W

woodbrian77

I've taken the following from a function. The function compiles
using both g++ 4.8 and VC++ 11.

std::vector<std::string*> rep20;
uint32_t elements = buf.Give<uint32_t>();
rep20.reserve(elements);
for (; elements > 0; --elements) {
rep20.push_back(buf.stringGive());
}


stringGive has this signature:
::std::string stringGive ();

I'd expect an error or warning so am wondering what's up
with this. (This code is part of my test code and not
something I'm using in an application.) Tia.


Shalom,
Brian
Ebenezer Enterprises
http://webEbenezer.net
 
W

woodbrian77

I've taken that from a function template and I'm
not calling an instance of the function. Still I
thought this would be caught.
 
I

Ian Collins

I've taken the following from a function. The function compiles
using both g++ 4.8 and VC++ 11.

std::vector<std::string*> rep20;
uint32_t elements = buf.Give<uint32_t>();
rep20.reserve(elements);
for (; elements> 0; --elements) {
rep20.push_back(buf.stringGive());
}


stringGive has this signature:
::std::string stringGive ();

Show the full declaration. If what you say is true, it shouldn't compile.
 
B

Bo Persson

(e-mail address removed) skrev 2012-06-21 04:57:
I've taken that from a function template and I'm
not calling an instance of the function. Still I
thought this would be caught.

If the template is never instantiated, the compiler is not allowed to
complain, unless the code cannot be correct for ANY type.



Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top