Standard says (draft N3690; this is post C++11, pre C++14):
[res.on.functions]
1 In certain cases (replacement functions, handler functions,
operations on types used to instantiate standard library template
components), the C++standard library depends on components supplied by
a C++program. If these components do not meet their requirements,
the Standard places no requirements on the implementation.
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.
Given that standard places no requirements, and effects are undefined (as far as I can tell, this is same as undefined behaviour), there is no expectation for the instantiation to "not work" any more than there is expectation for it to (appear to) "work".
Since C++17, the requirement was relaxed and std::vector
does not require the value type to be complete, if used with appropriate allocator (the default allocator is appropriate). (This freedom does not extend to using all member functions; they have additional requirements).
Standard quote (current draft):
[vector.overview]
An incomplete type T may be used when instantiating vector if the allocator meets the allocator completeness requirements.
T shall be complete before any member of the resulting specialization of vector is referenced.
[allocator.requirements.completeness]
If X is an allocator class for type T, X additionally meets the allocator completeness requirements if, whether or not T is a complete type:
- X is a complete type, and
- all the member types of allocator_-traits other than value_-type are complete types.
[default.allocator]
All specializations of the default allocator meet the allocator completeness requirements ([allocator.requirements.completeness]).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…