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

c++/509: G++ forbids template specialization as ambiguous



>Number:         509
>Category:       c++
>Synopsis:       G++ forbids template specialization as ambiguous
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 06 01:06:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Bangerth
>Release:        unknown-1.0
>Organization:
>Environment:
gcc 2.95.2 and 20000905	
>Description:
g++ rejects this code
-----------------------
template <class T>
struct Example {
                        void f (double);
    template <class U>  void f (U);
};

// specialize class template member function -- ambiguous?
template <>             void Example<double>::f (double);

// specialize class template member function template -- ok!
template <> template <> void Example<double>::f<double> (double);
---------------------------
with the following error message:
y.cc:8: ambiguous template specialization `f<>' for `Example<double>::f(double)'
y.cc:3: candidates are: void Example<double>::f(double)
y.cc:4:                 template <class U> void Example<double>::f<U>(U)

I am trying to specilize the non-template version of `f',
but I guess the ambiguity is not really present.

That such a construction is possible seems plausible to me from
[14.7.3.15]. Section [14.7.3.9] states how to handle such
amibuities, but is not exactly applicable here, as it only talks
about declarations with the same number of template parameters. This
is not the case here. I couldn't find any other place in the
standard talking about this.

One would think that by analogy, here the syntax would be
nonambiguous if the second `f' is prepended by `<double>' and the
first is not (as it is not a member template), but then the last of
the examples in [14.7.3.9] would not be conforming either. On the
other hand, the number of `template<>' pieces in front should be
significant to resolve the ambiguity, but this information seems to
not be used here.

Regards
  Wolfgang
>How-To-Repeat:
gcc y.cc
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

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