Topic: Exception specification in template friend functions


Author: "Andrei Iltchenko" <iltchenko@yahoo.com>
Date: Fri, 30 Mar 2001 21:24:54 GMT
Raw View
Artem Bezrodnov <darth@pt.comcor.ru> wrote in message
news:99rip1$7os$1@newsflood.tokyo.att.ne.jp...
> Dear all,
>
> I have the following code:
>
> template <class T> inline bool f(T& _refT) throw();
>
> class A {
>     template <class T> friend inline bool f(T& _refT) throw(); // line 4
> };
>
> int main() {
>     A l_a;
>     int l_iK = 0;
>     bool l_bK = f<int>(l_iK);
>     ...
> }
>
> template <class T> inline bool f(T& _refT)  throw()
> {
>     ...
>     return true;
> }
>
> It complies fine with GCC 2.95.2 and VisualAge C++ 4, but wouldn't compile
> with SUN WS6U1 C++, saying "line 4: Error: The prior declaration for
> f(A::T&) has an exception specification."
There's nothing wrong with the above code of yours, so a conforming
implementation shall accept and compile it.

> Does the standard say anything
> about exception specification for template friend functions?
The standard insists that if any declaration of a given function (be that a
template or a non-template function) has an exception specification, then
all the other declarations of that function (including its definition and
explicit specialization) must have the same exception specification. There
is really nothing special about one of the three declarations being a friend
of the class A, as the friend declaration merely refers to the function
template declaration declared prior to it in global scope.


Sincerely,

Andrei Iltchenko.


---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: "Artem Bezrodnov" <darth@pt.comcor.ru>
Date: Tue, 27 Mar 2001 23:16:02 CST
Raw View
Dear all,

I have the following code:

template <class T> inline bool f(T& _refT) throw();

class A {
    template <class T> friend inline bool f(T& _refT) throw(); // line 4
};

int main() {
    A l_a;
    int l_iK = 0;
    bool l_bK = f<int>(l_iK);
    ...
}

template <class T> inline bool f(T& _refT)  throw()
{
    ...
    return true;
}

It complies fine with GCC 2.95.2 and VisualAge C++ 4, but wouldn't compile
with SUN WS6U1 C++, saying "line 4: Error: The prior declaration for
f(A::T&) has an exception specification." Does the standard say anything
about exception specification for template friend functions? Thanks in
advance!

Artem


---
[ 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://www.research.att.com/~austern/csc/faq.html                ]