The standard requires that, all types used in template components of the standard library must be complete, unless otherwise stated. Thus libc++’s error is correct. Using an incomplete type is undefined behavior (§17.6.4.8[res.on.functions]/2), so libstdc++ accepting it isn’t wrong either.
You could use a pointer object to construct the complete type as you did. But you could also use some third-party collections library which allows incomplete types, e.g. boost::container::map
is designed to allow incomplete types.
§17.6.4.8 Other functions / 2:
In particular, the effects are undefined in the following cases:
…
if an incomplete type (3.9) is used as a template argument when instantiating a template component, unless specifically allowed for that component.
(The only components that explicitly allow incomplete types are declval
, unique_ptr
, default_delete
, shared_ptr
, weak_ptr
and enable_shared_from_this
.)