This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Make parser revert digraph "<:"


"Zack Weinberg" <zack@codesourcery.com> writes:

| Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| 
| > | While this diagnostic is technically more accurate, I think it's both
| > | more confusing and poorer English.  How's this?
| > | 
| > | error: '<::' cannot begin a template-argument list
| >
| > The confusing thing about this suggestion is that the beginning of the
| > template-argument list is not '<::'.
| 
| But it is '<::', in the most important place: in the source file. 

Yes, but it is not the beginning of the template-argument list!  
The beginning is the single character '<'.

| The programmer wrote
| 
|  T<::whatever>
| 
| and that is what s/he will see in a text editor, so the error message
| is most helpful by using that sequence of symbols.

Sure.  And previous suggestions have been also been talking about
that sequence in various ways.  What is wrong about it is saying that 
"'<::' cannot begin a template-argument list", because, when the
programmer writes 

   T<::whatever>

he/she intends to have '::' part of 'whatever' -- and in essence, that
is what it is supposed to mean: '::' qualifies 'whatever'.  
So the formulation we're looking for should not associate '<::' with
the beinning of a template-argument list.

| It is vanishingly
| unlikely that the programmer actually wrote T <: : whatever; cpplib
| does give the ability to test for this, via the PREV_WHITE flag on the
| : token, but I doubt it is worthwhile.

And I doubt that is even useful.

| > It is like writing
| >
| >     +++i
| >
| > which gets lexed as ++ + i and not + ++ i.  How would you phrase  the
| > diagnostic for that?
| 
| "+++i" is a valid C99 unary-expression.  It is semantically invalid,
| because "+i" is not a modifiable lvalue, but it parses.  So I would
| say something like
| 
| error: invalid lvalue in increment
| note: "+++" is parsed as "++ +" not "+ ++"
| 
| assuming that it is possible to detect this case at the point where
| the invalid lvalue diagnostic issues.
| 
| > Yes, that is one of the items on the C++ Evolution Working Group wishlist
| > we would like to address as cleanly as possible.
| 
| May I suggest that a plausible (and generally helpful, not just with
| templates) first step would be
| 
| #pragma STDCXX (DIGRAPHS|TRIGRAPHS) (ON|OFF)
| 
| ?  This would be trivial to implement under the #pragma GCC namespace
| as a demonstration.

I'm afraid anything that starts with pragma is not a first step.  This
kind of thing can be handled without pragma/dogma intervening.  I've
already seen a patch for the ">>" thingy.  The one proposed by
Giovanni can be handled without pragma -- in fact, instead of issueing
a diagnostic we could just accept the code (assuming the token was not
spelt '[').

| > Also, see suggestion ES018 at
| >
| >     http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1512.html
| >
| > for things like
| >
| >     vector<list<int>> vl;
| 
| What is GJ?

I don't understand what you mean by "GJ".

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]