James Kuyper said:
That was my point, but I forgot to make it. One alternative is to create
a special case for source code files whose first three characters are
??=. I don't approve of such special-casing, but it would be feasible.
I wouldn't want to require it to be the very first three characters
of the file; it should be able to follow empty lines, whitespace,
and comments. And it probably should apply only to the current file,
not to any #included files.
Any change that disables trigraphs by default will break existing
code that depends on them. Adding a single line to the top of each
affected source file *seems* easy enough, but managing all those
source code changes could be a nightmare.
On the other hand, perhaps the compatibility problem is more
theoretical than real. If, say, C2020 disabled trigraphs by default
(with or without providing a way to enable them), it would only
break code on systems that (a) actually need trigraphs, and (b)
have compilers that are upgraded to support the C2020 standard.
In practice, that may well be the empty set. And there's no reason
a C2020 compiler for such a platform couldn't have an extension
that solves the same problem trigraphs solve. (I'm ignoring code
that deliberately uses trigraphs on systems that don't actually
require them; is there any significant amount of such code outside
test suites?)
One problem with
??=pragma STDC TRIGRAPH ON
and similar suggestions is that they make code that uses them
incompatible with *earlier* versions of the standard. You could
permit
??=if __STDC_VERSION__ >= 202001L
??=pragma STDC TRIGRAPH ON
??=endif
but that's even uglier.
Perhaps a stylized comment could be used to enable trigraphs; if the
first comment in a source file contains, say, "ENABLE TRIGRAPHS",
then trigraphs are enabled.
There are a multitude of possible solutions to the "trigraph
problem". There seem to be exactly zero *clean* solutions, and I'm
beginning to think that the actual magnitude of the problem doesn't
justify any of them. I think we're just going to have to live with
trigraphs -- unless the committee can be persuaded to just remove
them from the language altogether.