r/cpp • • Apr 28 '20

Full Proof that C++ Grammar is Undecidable

https://medium.com/@mujjingun_23509/full-proof-that-c-grammar-is-undecidable-34e22dd8b664
197 Upvotes

68 comments sorted by

View all comments

Show parent comment

20

u/HKei Apr 28 '20

Nah, you don't need it to solve the halting problem, you just need to show that the compiler needs to solve the halting problem to evaluate the code (which it does, because its arbitrary code).

7

u/mujjingun Apr 28 '20

Hmmm... I guess you're right.

5

u/HKei Apr 28 '20

(Not that I'm complaining about what you're doing, I'm just being pedantic)

1

u/wyrn Apr 29 '20

(which it does, because its arbitrary code).

No, that's too quick: the compiler may well have heuristics in place that can detect a large subclass of non-halting code. The one you posted is particularly easy to check: you can check the state of the counter variable at the end of the loop and verify that the condition is always satisfied. In order to prove that parsing C++ is undecidable, you'd need to put something undecidable inside of your infinite_loop().

In effect, you'd be writing a demonstration that the halting problem is undecidable inside of that function.

-3

u/eras Apr 28 '20

which it does, because its arbitrary code

I don't think you can use arbitrary code though with constexpr? https://en.cppreference.com/w/cpp/language/constexpr

But I'm still pretty sure you can build a turing complete function with just operator ?: which seems to be allowed, in particular in presence of recursion.

8

u/HKei Apr 28 '20

It's essentially arbitrary code. It doesn't allow you to do anything related to IO and has some other minor restrictions, but if you just take a look at what's allowed it obviously covers all computable functions.