Sign in to follow this  

Standards compliance question

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

To my suprise, VS2008 permits the following:
class Node
{
public:
	std::list<Node> nodes;
};
and
class Node;

std::list<Node> nodes;

class Node
{
};
without complaint. Borland BCC55 complains, as I would have expected, that Node is used before it is defined. Since VS2008 does not permit:
class Node
{
public:
    Node n; // error, as you would expect
};
I'm guessing that it must be down to differences in the way that std::list<> is implemented by the two distributions. Is that correct, and if so, does anyone happen to know whether the standard dictates that you should be able to declare a std::list<> with a type that has not been defined? Is VS being lenient, or is BCC55 failing a standards compliance? Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
The standard requires that containers be used with complete types. For more information see this article.


Thanks. That figures. Any idea why, or even how, VS permits this code to compile and work? Is this undefined behaviour territory, as the code based upon the example above has been extensively tested and seems fine.

[EDIT]

The article answered my question:

Quote:

The C++ Standard [8] says that you're not allowed to instantiate a standard library template with an incomplete type: "the effects are undefined ... if an incomplete type is used as a template argument when instantiating a template component." Some implementations do permit it in some circumstances, but that's just an accident. (Remember, "undefined behavior" covers absolutely anything — including things working as you might expect them to!)


Shame. Interesting stuff though.

Share this post


Link to post
Share on other sites

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this