This is the mail archive of the gcc-bugs@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]

[Bug c++/50080] New: error: 'template' (as a disambiguator) is only allowed within templates


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50080

             Bug #: 50080
           Summary: error: 'template' (as a disambiguator) is only allowed
                    within templates
    Classification: Unclassified
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: solodon@mail.com


Hi,

Consider the following code snippet compiled as:

g++ -std=c++0x test.cpp

In particular the two instantiations of B: one in the template context and the
other one in non-dependent scope.

template <typename T>
struct A
{
    template <typename U>
    struct B {};
};

template <typename T>
void test()
{
    typename A<T>::template B<int> b;
}

int main()
{
    typename A<double>::template B<int> b;
}

My GCC complains about the second instantiation saying: 

error: 'template' (as a disambiguator) is only allowed within templates

and surely enough removing template there fixes the problem. The keyword
typename used for a similar purpose of disambiguating a type in a non-template
context is accepted even though redundant. Allowing typename seems to be in
line with the relaxed rule of C++0x. I think, however, that the template
keyword should similarly be allowed in non-dependent context accordingly to the
C++0x standard (and not allowed accordingly to C++03).

Here is a snippet from C++0x standard draft (FDIS n3291, section 14.2[5]) I
could get a hold of:

``A name prefixed by the keyword template shall be a template-id or the name
shall refer to a class template.
[ Note: The keyword template may not be applied to non-template members of
class templates. -end
note ] [ Note: As is the case with the typename prefix, the template prefix is
allowed in cases where it is
not strictly necessary; i.e., when the nested-name-specifier or the expression
on the left of the -> or . is not
dependent on a template-parameter, or the use does not appear in the scope of a
template. -end note ]''

I think that the second note implies that template keyword should have been
allowed in the example above in much the same way the typename is, please
correct me if I'm wrong.

The practical reason I need this behavior for is that I have a code snippet
that is generated by a macro. With template being allowed in non-dependent
context I can have a single macro that can be used in dependent and
non-dependent contexts, while without this behavior (as well as in C++03) I
will need to have 2 separate (largely duplicated) macros for each of the uses.

Thanks,
Yuriy


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