incomplete type for std::unordered_set compiling error in g++5, compiles in clang++

后端 未结 1 1172
轻奢々
轻奢々 2021-01-22 22:50

Consider the code related to a previous SO question C++ cyclic dependency confusion with adjacency list representation

#include 
#include 

        
相关标签:
1条回答
  • 2021-01-22 23:33

    It is undefined behavior to instantiate a standard library container with an incomplete type. [res.on.functions]/1, 2.5:

    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.

    Both implementations are correct.

    There is currently a proposal to add incomplete type support to some containers, but it is limited to vector, list and forward_list.

    0 讨论(0)
提交回复
热议问题