From: Felipe Magno de Almeida on
On Aug 4, 1:30 am, Walter Bright <newshou...(a)digitalmars.com> wrote:
> Nikolay Ivchenkov wrote:
> > A declaration cannot consist of arbitrary sequence of tokens (see C+
> > +03 - [dcl.dcl]). There are no special exceptions for templates in
> > this respect. Thus, the syntax of any template must be completely
> > checked regardless of whether the template is instantiated.
>
> This is the template definition part which is stored as a sequence of tokens
> until instantiation time, not the declaration. The declarations are always
> parsed and checked, even if never used.
>
> My reading of C++98 was that the compiler was not required to issue a diagnostic
> for a malformed definition if it was never instantiated.

Unless I'm missing something, I think it is required to diagnose.
After all, if you implement Two Phase Lookup then you must make the
first lookup
when you first parse the template.

> --

Regards,
--
Felipe Magno de Almeida


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Nikolay Ivchenkov on
On 4 Aug, 08:30, Walter Bright <newshou...(a)digitalmars.com> wrote:
> Nikolay Ivchenkov wrote:
> > A declaration cannot consist of arbitrary sequence of tokens (see C+
> > +03 - [dcl.dcl]). There are no special exceptions for templates in
> > this respect. Thus, the syntax of any template must be completely
> > checked regardless of whether the template is instantiated.
>
> This is the template definition part which is stored as a sequence of tokens
> until instantiation time, not the declaration.

Every template definition is a template declaration. For example, in
the following template definition

template <class T>
void f() { T::g(); }

every its token is a part of the template-declaration. According to
the syntactic rules, the following sequence of tokens

template <class T>
void f() { T + 1; }

cannot be considered as a template-declaration at all.

> My reading of C++98 was that the compiler was not required to issue a diagnostic
> for a malformed definition if it was never instantiated.

What's the malformed definition? (I want to see normative criteria if
they exist). For example, can we consider the following sequence of
tokens

%+*!^~

as a malformed template definition (according to your interpretation)?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Walter Bright on
Nikolay Ivchenkov wrote:
> On 4 Aug, 08:30, Walter Bright <newshou...(a)digitalmars.com> wrote:
>> My reading of C++98 was that the compiler was not required to issue a diagnostic
>> for a malformed definition if it was never instantiated.
>
> What's the malformed definition?

One that doesn't follow the grammar.

> (I want to see normative criteria if
> they exist). For example, can we consider the following sequence of
> tokens
>
> %+*!^~
>
> as a malformed template definition (according to your interpretation)?

Yes.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Walter Bright on
Felipe Magno de Almeida wrote:
> On Aug 4, 1:30 am, Walter Bright <newshou...(a)digitalmars.com> wrote:
>> My reading of C++98 was that the compiler was not required to issue a diagnostic
>> for a malformed definition if it was never instantiated.
>
> Unless I'm missing something, I think it is required to diagnose.

At this point, I'll require a specific quote from C++98 <g>.


> After all, if you implement Two Phase Lookup then you must make the
> first lookup
> when you first parse the template.

The Digital Mars C++ does implement two phase lookup correctly, so
preparsing
the template definitions is not required in order to get that right.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: CornedBee on
On Aug 4, 7:15 pm, Walter Bright <newshou...(a)digitalmars.com> wrote:
> Felipe Magno de Almeida wrote:
>
>> On Aug 4, 1:30 am, Walter Bright <newshou...(a)digitalmars.com> wrote:
>>> My reading of C++98 was that the compiler was not required to issue a diagnostic
>>> for a malformed definition if it was never instantiated.
>
>> Unless I'm missing something, I think it is required to diagnose.
>
> At this point, I'll require a specific quote from C++98 <g>.

[temp.res]p8 gives an explicit example of completely nonsensical code
(not even syntactically correct), with the note that it *may* be
diagnosed even if the template is never instantiated. In other words,
as long as a template is not instantiated, you can have whatever you
want in there, as long as the parser is still able to find the end of
the template. Getting diagnostics early is simply a QoI issue.
Clang aims at diagnosing things as early as possible and as thoroughly
as possible (there are many things in the area that are ill-formed, no
diagnostic required; we want to diagnose them), so blindly caching
tokens is simply not an option. We would have to cache them and parse
them at definition time, and then parse them again at instantiation
time. (For every instantiation, of course.) Now *that* is a waste of
effort.

Sebastian


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: basic concatenation question
Next: type casting issue