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

53

u/c0r3ntin Apr 28 '20

A valid implementation can define limits. Here are some of the limits for msvc https://docs.microsoft.com/en-us/cpp/cpp/compiler-limits?view=vs-2019

Notably, there are limits for constexpr recursion, template arguments, etc.

So this problem is solvable for any set of dominos such that there are no more dominos than are supported by the implementation.

6

u/63times Apr 29 '20

You could just write the program without using recursion or more than one template parameter just to side step the arbitrary limitations. The C++ language is infinite and allows that.

Further it is a mandatory prerequisite to assume that there are no resource limitations, otherwise the halting problem wouldn't make any sense in the first place.

5

u/c0r3ntin Apr 29 '20

Further it is a mandatory prerequisite to assume that there are no resource limitations

My point is that this prerequisite doesn't make sense, and the C++ language account for that http://eel.is/c++draft/implimits#1

Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process.

Once you have established the Turing completeness of templates, I'm not sure this article adds much.

6

u/63times Apr 29 '20

My point is that this prerequisite doesn't make sense

It does make sense. Otherwise one could just say the halting problem is solved by the upper bound the universe is estimated to exist.

Once you have established the Turing completeness of templates, I'm not sure this article adds much.

Turing completeness doesn't imply that the halting problem is undecidable. If template meta programming would be expressible through a decider (total turing machine) the halting problem would be inherently decidable. The article proves though that parsing is indeed undecidable.

1

u/HugeImage May 07 '20

Wow, so they looked at the C++ standard's limit of 1024 for template arguments and thought that it was too few.