Yes, there are valid C++ programs which include the sequence of characters :::
(outside of comments and quoted literals).
Normally, that sequence would be lexically analysed as a ::
token (the scope resolution operator) followed by a :
token. As far as I know, there is no valid C program of this form, because a :
can only be preceded by a name (as a label) or an expression (either in a case
label or as part of the ternary ?:
operator). And ::
cannot be the last token in an expression.
You can force the lexical analyser to produce a :
followed by a ::
but only by placing whitespace between the two tokens, making : ::
. And, of course, you can use the preprocessor to define a macro which ignores or stringifies an argument, so :::
could appear as an argument to such a macro.
Leaving those aside, as far as I know the only possibility is when the first :
is the second character in a <:
token. For example:
const int size = 42;
int A<:::size:>;
(Live on coliru.)
If that looks weird, remember that <:
is an alternative spelling for [
and :>
is an alternative spelling for ]
. The unary scope resolution operator ::
indicates that the name it qualifies is in global scope.
Curiously, <::
is an exception to the maximal-munch rule if it is not followed by :
or >
, in which case it must be analysed as <
followed by ::
rather than as <:
followed by :
. However, when it is followed by :
(as above) or >
, maximal munch still applies and the first token is <:
.