Topic: Default expressions and template-ids


Author: "John Wiegley" <jwiegley@inprise.com>
Date: 1998/07/27
Raw View
To: C++ core language mailing list
Message c++std-core-7773

Given the following code:

    template <class T, class U>
    void foo(T a, U b);

    template <class T>
    class baz {
    public:
        void bar(int a = blah<int, char>(1, 1));
        void baw(int a = blaz < 0, int b = job - 10);
        void bat(int a = blaz < 0, int b = job > 10);
    };

I have this quandry while attempting to parse the default expressions
of the above member functions:

    baz::bar - If 'blah' is a template, then this is a normal
               template-id and everything is OK.  If 'blah' is
               not a template, then it is a syntax error because
               it's trying to see if 'blah' is less than a type.

    baz::baw - In this case, the programmer is assuming that 'blaz'
               is a variable, but what if it's a template?  Then we
               have an unterminated explicit argument list.  The
               more important point is that since the standard
               doesn't require a declaration for 'blaz' in this
               context (since we haven't actually called the function
               yet in a situation where the default expression would
               be required), then how do I know what to do with this?

    baz::bat - Same problem.  Does the '>' terminate an explicit
               argument list, or is it a greater-than symbol in the
               second default expression.  Some might think that the
               syntax error encountered when assuming that it's an
               explicit argument list would disqualify that option,
               but remember that I can't know the syntatic role of
               'blaz' at the time of declaration.

All of these problems can be avoid in the qualified-id case, where
the "template" keyword is used.  As in:

    void bar(int a = N::template blah<int, char>(1, 1));

But in the unqualified case, I don't know what to do.  Just assume
that its never a template?  If I were to require the 'template'
keyword in these cases, it would solve the problem as well, but I
don't see any justification for this in the standard.

As a side note, Borland, Microsoft and GCC all report an error, because
they assume non-templates in all cases.  Does anybody know what should
be done here?

John
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]