C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why does this compile?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Jun 21, 2012 2:48 am    Post subject: Why does this compile? Reply with 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 ();

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





PostPosted: Thu Jun 21, 2012 2:48 am    Post subject: Re: Why does this compile? Reply with quote



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






PostPosted: Thu Jun 21, 2012 2:57 am    Post subject: Re: Why does this compile? Reply with 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.
Back to top
Bo Persson
Guest





PostPosted: Sat Jun 23, 2012 6:11 am    Post subject: Re: Why does this compile? Reply with quote

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
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group