Is segmentation fault actual undefined behavior when we refer to a non-static data-member

前端 未结 3 1462
悲哀的现实
悲哀的现实 2020-11-21 05:17

I had read the following rule and I\'ve been trying to write an example, which reflects one. The rule is from 3.8/5 N3797:

Before the lifetime of an o

3条回答
  •  没有蜡笔的小新
    2020-11-21 05:55

    You asked:

    Is it true that in the case //1 is well-formed and doesn't cause any UB?

    The parts of the standard you quoted does not mention anything about it.

    You also asked:

    but //2 produced segmentation fault, which is UB?

    The parts of the standard you quoted does not correspond to this particular behavior. You are seeing UB because of where p points. It points to memory that does not hold a valid object.

提交回复
热议问题