37

C++17 removed trigraphs. IBM heavily opposed this (here and here) so there seem to be arguments for both sides of removal/non removal.

But since the decision was made to remove trigraphs, why leave digraphs? I don't see any reasons for keeping digraphs beyond the reasons to keep trigraphs (which apparently didn't weight enough to keep them).

6
  • 17
    It's nearly Christmas, so disallowing smileys with beards would be sad.
    – user1804599
    Commented Dec 22, 2014 at 11:25
  • 1
    Note that trigraphs are being deprecated and not removed. I think that the idea is to get people who might be using them to stop using them in new code and to get developers with old code to migrate eventually. They won't be breaking code - as for why: it's just another way to do the same thing which makes the language just a tiny bit bigger and more confusing. Commented Dec 22, 2014 at 11:29
  • @BenjaminGruenbaum As far as I know, they'll be gone completely in C++17
    – Xeo
    Commented Dec 22, 2014 at 11:47
  • 3
    @BenjaminGruenbaum they were proposed for deprecation in C++11 but that did not pass. In C++17 they were voted for removal
    – bolov
    Commented Dec 22, 2014 at 12:03
  • 9
    I don't know how the discussion went down (hence not an answer), but probably it's because the burden of keeping digraphs is lower. Since they're not replaced in comments or string literals, you don't use them accidentally. Commented Dec 28, 2014 at 17:04

1 Answer 1

44

Trigraphs are more problematic to the unaware user than digraphs. This is because they are replaced within string literals and comments. Here are some examples…

Example A:

std::string example = "What??!??!";
std::cout << example << std::endl;

What|| will be printed to the console. This is because of the trigraph ??! being translated to |.

Example B:

// Error ?!?!?!??!??/
std::cout << "There was an error!" << std::endl;

Nothing will happen at all. This is because ??/ translates to \, which escapes the newline character and results in the next line being commented out.

Example C:

// This makes no sense ?!?!!?!??!??/
std::string example = "Hello World";
std::cout << example << std::endl;

This will give an error along the lines of use of undeclared identifier "example" for the same reasons as Example B.

There are far more elaborate problems trigraphs can cause too, but you get the idea. It's worth noting that many compilers actually emit a warning when such translations are being made; yet another reason to always treat warnings as errors. However this is not required by the standard and therefore cannot be relied upon.

Digraphs are much less problematic than trigraphs, as they are not replaced inside another token (i.e. a string or character literal) and there is not a sequence that translates to \, so escaping new lines in comments cannot occur.

Conclusion

Other than harder to read code, there are less problems caused by digraphs and therefore the need to remove them is greatly reduced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.