This is the mail archive of the gcc@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: default int paramters ignored?


> 
> nbecker@hns.com (Neal D. Becker) writes:
> 
> |   Rnd b; << parse error
> 
> The above should read:
> 
>    Rnd<> b;
> 
> -- Gaby
> 

Right, but there is a quality-of-implementation issue here.
Given

template<int shift=1>
struct Rnd {
  inline int Compute (int x) {
    return x >> shift;
  }
};

main() {
  Rnd<1> a; // OK
  Rnd b;    // line 10: Error
}

We get

b.cxx: In function `int main()':
b.cxx:10: `Rnd' undeclared (first use this function)
b.cxx:10: (Each undeclared identifier is reported only once for each function 
   it appears in.)
b.cxx:10: parse error before `;' token

Rnd has not been declared as a value or a type, but it has been declared
as a template.  Arguably the message and possibly the error recovery
should be different, as omitting the template argument list is a common
syntax error.

Doing a fancier recovery should probably be postponed until the new parser
is used.  An intermediate solution might just look up the name as a
template after it is determined to be undeclared as an identifier,
and generate the error message in a different way, e.g.

b.cxx: In function `int main()':
b.cxx:10: A template name `Rnd' is being used where an identifier or type name is expected.
b.cxx:10: parse error before `;' token

that is, make no changes other than the text of the message that is
issued.


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