If you have a program that will unconditionally access uninitialized memory then the compiler can halt and emit a diagnostic. But that's rarely what is discussed in these UB conversations. Instead the compiler is encountering a program with multiple paths, some of which would encounter UB if taken. But the compiler cannot just refuse to compile this, since it is perfectly possible that the path is dead. Like, imagine this program:

    int foo(bool x, int* y) {
      if (x) return *y;
      return 0;
    } 
Dereferencing y would be UB. But maybe this function is called only with x=false when y is nullptr. This cannot be a compile error. So instead the compiler recognizes that certain program paths are illegal and uses that information during compilation.

Maybe we should make that an error.

More modern languages have indeed embedded nullability into the type system and will yell at you if you dereference a nullable pointer without a check. This is good.

Retrofitting this into C++ at the language level is impossible. At least without a huge change in priorities from the committee.

Maybe not the Standard, but maybe not impossible to retrofit into:

    -Werror -Wlet-me-stop-you-right-there