Documentation of “invalid pointer value” conversion in C++ implementations

后端 未结 1 1806
遇见更好的自我
遇见更好的自我 2020-12-17 15:14

According to the C++ Standard, it is mandatory for every implementation to document "implementation-defined behavior":

1.3.11 [defns.impl

相关标签:
1条回答
  • 2020-12-17 16:06

    CWG #1438 changed the semantics concerning invalid pointer values:

    The current Standard says that any use of an invalid pointer value produces undefined behavior (3.7.4.2 [basic.stc.dynamic.deallocation] paragraph 4). This includes not only dereferencing the pointer but even just fetching its value. The reason for this draconian restriction is that some architectures in the past used dedicated address registers for pointer loads and stores and they could fault if, for example, a segment number in a pointer was not currently mapped.

    It is not clear whether such restrictions are necessary with architectures currently in use or reasonably foreseen. This should be investigated to see if the restriction can be loosened to apply only to dereferencing the pointer.

    The change in [conv.lval] is the resolution of CWG #616, which essentially adopted the above.
    Lifting this from UB to implementation-defined behavior was intentional, so I presume the absence of this paragraph in the Index is an oversight.

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