Prev: basic concatenation question
Next: type casting issue
From: Walter Bright on 1 Aug 2010 14:51 CornedBee wrote: > I am pretty sure, from observing its behaviour, that MSVC caches the > token stream instead of building an AST, but that's not a good > approach: there are various bugs that can be traced to this > implementation choice. Please give an example. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Edward Rosten on 2 Aug 2010 03:50 On Aug 1, 3:48 pm, Walter Bright <newshou...(a)digitalmars.com> wrote: > Seima Rao wrote: > > Can readers of this forum advise on whether it would be > > fruitful to consider compiling C++ templates to > > IR instead of preprocessing them? > > Frankly, precompiling them is a waste of time and effort, in my not-so-humble > opinion. The Digital Mars C++ compiler stores template definitions as a sequence > of tokens. At instantiation time, it does the syntactic and semantic analysis in > one go. > > The Standard allows precompiling them into some syntactical intermediate form, > and there are some crutches in the syntax to allow this to work. It's my > understanding that this is how all the other C++ compilers handle it. I assume by this that you are referring to the need to scatter .template within templated code? I presume then that DMC++ doesn't need them (much like GCC 3.x series of compilers), and 4.x with appropriate compiler flags? > The > advantage of this approach is that some syntactical errors can be diagnosed > before instantiating the template. The disadvantage is it's significantly more > complex to implement. Not to mention making the template code somewhat nastier to read, if my above assumption is correct. -Ed -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Walter Bright on 2 Aug 2010 21:47 Edward Rosten wrote: > On Aug 1, 3:48 pm, Walter Bright <newshou...(a)digitalmars.com> wrote: >> Frankly, precompiling them is a waste of time and effort, in my not-so-humble >> opinion. The Digital Mars C++ compiler stores template definitions as a sequence >> of tokens. At instantiation time, it does the syntactic and semantic analysis in >> one go. >> >> The Standard allows precompiling them into some syntactical intermediate form, >> and there are some crutches in the syntax to allow this to work. It's my >> understanding that this is how all the other C++ compilers handle it. > I assume by this that you are referring to the need to > scatter .template within templated code? I presume then that DMC++ > doesn't need them (much like GCC 3.x series of compilers), and 4.x > with appropriate compiler flags? Right, it doesn't need them, though in order to be Standard compliant the parser gives an error if they aren't there! -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Nikolay Ivchenkov on 3 Aug 2010 07:17 On 1 Aug, 18:48, Walter Bright <newshou...(a)digitalmars.com> wrote: > Seima Rao wrote: > > Can readers of this forum advise on whether it would be > > fruitful to consider compiling C++ templates to > > IR instead of preprocessing them? > > Frankly, precompiling them is a waste of time and effort, in my not-so-humble > opinion. The Digital Mars C++ compiler stores template definitions as a sequence > of tokens. At instantiation time, it does the syntactic and semantic analysis in > one go. According to syntactic rules, a sequence of tokens can be considered as a template declaration (and possibly a template definition) _only if_ the sequence satisfies the syntactic rules for template declarations (see below). Otherwise if the program would be syntactically incorrect, a diagnostic message shall be issued in most cases. (Of course, a compiler - like yours - can violate standard requirements and, in particular, do not provide diagnostics when it is required by the standard). template-declaration: export opt template < template-parameter-list > declaration 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. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Walter Bright on 3 Aug 2010 13:30
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. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |