Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nope. C++ really does deliberately require that compilers will in some cases emit a program which does... something even though what you wrote isn't a C++ program.

Yes, that's very stupid, but they did it with eyes open, it's not a mistake. In the C++ ISO document the words you're looking are roughly (exact phrasing varies from one clause to another) Ill-formed No Diagnostic Required (abbreviated as IFNDR).

What this means is that these programs are Ill-formed (not C++ programs) but they compile anyway (No diagnostic is required - a diagnostic would be an error or warning).

Why do this? Well because of Rice's Theorem. They want a lot of tricky semantic requirements for their language but Rice showed (back in like 1950) that all the non-trivial semantic requirements are Undecidable. So it's impossible for the compiler to correctly diagnose these for all cases. Now, you could (and Rust does) choose to say if we're not sure we'll reject the program. But C++ chose the exact opposite path.





I'm not sure what your replying to, but it can't be my comment because what you're saying has absolutely nothing to do with it.

But kudos to you on writing an irrelevant wall of text.


It does. The UB is false positives to the question "Is this a valid program".

No one disputes that C++ accepts some invalid programs, I never claimed otherwise. I said that C++'s type system will reject some programs that are in principle correct, as opposed to what Spivak originally claimed about C++ accepting all correct programs as valid.

The fact that some people can only think in terms of all or nothing is really saying a lot about the quality of discourse on this topic. There is a huge middle ground here and difficult trade-offs that C++ and Rust make.


Sorry, then I misunderstood you, do you have an example, of a correct rejected C++ program?

Many cases that require any kind of cast are this.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: