 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Jun 21, 2012 2:48 am Post subject: Why does this compile? |
|
|
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 |
|
| Back to top |
|
 |
Ian Collins Guest
|
Posted: Thu Jun 21, 2012 2:48 am Post subject: Re: Why does this compile? |
|
|
On 06/21/12 02:48 PM, woodbrian77 (AT) gmail (DOT) com wrote:
| Quote: | 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.
--
Ian Collins |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Jun 21, 2012 2:57 am Post subject: Re: Why does this compile? |
|
|
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. |
|
| Back to top |
|
 |
Bo Persson Guest
|
Posted: Sat Jun 23, 2012 6:11 am Post subject: Re: Why does this compile? |
|
|
woodbrian77 (AT) gmail (DOT) com skrev 2012-06-21 04:57:
| Quote: |
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 |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|