News for hackers. Stuff that matters.
Re:How to abuse a C++ compiler? by Tobu on Thursday March 20, 2014 @09:36AM (#7435407)
Clang is mathematically wrong in all but the first case. I'm not sure what it says about C++ conformance; the problem is likely Clang but I'm not sure how sound template metaprogramming or C++ templates are supposed to be.
Re:How to abuse a C++ compiler? by aidenn0 on Thursday March 20, 2014 @12:10PM (#7436415)
As others have noted, infinite template recursion is undefined. It could produce a program that does whatever it wants and still be conforming.
Re:How to abuse a C++ compiler? by Tobu on Thursday March 20, 2014 @07:05PM (#7439498)
So the lack of soundness is in the C++ templates spec.

Nevertheless, I think it's bad form for a compiler to take full advantage of undefined behaviour. Reinterpreting undefined behaviour as “should not compile” (failing that, “must crash”) is possible for almost all of C99; CompCert (formally verified C compiler) obviously does it, and the implementation is the easy part (formal verification being the complicated part).

Re:How to abuse a C++ compiler? by cbsmith on Thursday March 20, 2014 @10:10PM (#7440255)
> So the lack of soundness is in the C++ templates spec.

That's not a lack of soundness. It's a lack of specificity. For cases like this, that's actually a feature, not a bug.

> Nevertheless, I think it's bad form for a compiler to take full advantage of undefined behaviour.

What exactly is "take full advantage of undefined behaviour"? Isn't any behaviour just as different from "undefined" as anything else?

> Reinterpreting undefined behaviour as “should not compile” (failing that, “must crash”) is possible for almost all of C99; CompCert (formally verified C compiler) obviously does it, and the implementation is the easy part (formal verification being the complicated part).

Clang not only has an ability to do this, it includes a flag to do a quick check specifically for undefined behaviour as well as an ability to provide a trap for undefined behaviour, which is terribly useful for tool builders.

Re:How to abuse a C++ compiler? by aidenn0 on Friday March 28, 2014 @12:47AM (#7485399)
So a compiler must emit a check for signed integer overflow on every integer operation? That seems absurd. It makes sense to optionally instrument for that (as clang offers) but is otherwise ridiculous.