Does the C++ standard specify the type dependencies of standard containers?

Viewed 110

In "Codependent types with unordered_map" it was observed that std::unordered_map<Key, Value> has a type dependency on Value in libstdc++ (which is unexpected) and has no type dependency on Value in libc++ and MSVC.

In general, does the ISO C++ specification talk about the type dependencies of containers at all? If so could you point me to relevant parts?

Type dependency: I'm not sure if there is a formal definition of type dependency in the ISO C++ spec, but for the purposes of this post, let us say a type A has type dependency on type B if A cannot be compiled with the forward declaration of B alone. Example:

struct Val; // forward declaration of Val
struct Container {
  Val v;
}; // Compile error; Type Val is incomplete. Container has a type dependency on Val
struct Val; // forward declaration of Val
struct Container2 {
  Val *v;
}; // Compiles. Container2 does not have type dependency on Val
1 Answers

You might be looking for this:

[res.on.functions]/2 In particular, the effects are undefined in the following cases:

...

(2.5) — if an incomplete type (6.9) is used as a template argument when instantiating a template component, unless specifically allowed for that component.


Of various standard containers, [containers] section specifies that std::forward_list, std::list and std::vector can be instantiated with incomplete types. E.g.

[vector.overview]/3 An incomplete type T may be used when instantiating vector if the allocator satisfies the allocator completeness requirements (20.5.3.5.1). T shall be complete before any member of the resulting specialization of vector is referenced.

There's similar wording for forward_list and list.

Related