Topic: Who is right - Sun C++ or SGI STL?


Author: saroj@my-dejanews.com
Date: 1998/07/26
Raw View
Hi,

I have a question about this piece of code and I'd like to
know what the standard says.

template <class _CharT, class _Alloc>
class rope
{
  ....
  friend rope<_CharT,_Alloc>   /* no inline here */
  operator+ __STL_NULL_TMPL_ARGS (const rope<_CharT,_Alloc>& __left,
                            const rope<_CharT,_Alloc>& __right);
  ...
};

...

template <class _CharT, class _Alloc>
inline   /* note the inline here */
rope<_CharT,_Alloc>
operator+ (const rope<_CharT,_Alloc>& __left,
           const rope<_CharT,_Alloc>& __right)
{
...
}

When used in a program, Sun compiler fails to link saying
operator+(const rope&, const rope&) is not defined. Basically
the absence of inline in the friend declaration makes it think
that operator+ has external linkage and it does not notice
inline later. Is it a bug in Sun C++ or should the 'inline'
be added to the friend declaration?

Another question:

template<class _CharT, class _Alloc>
struct _Rope_RopeRep
{
  ....
  static void _S_free_string(__GC_CONST _CharT*, size_t __len,
               allocator_type __a);  /* no inline here */
  ...
};

template<class _CharT, class _Alloc>
struct _Rope_RopeLeaf
{
  ...
  ~_Rope_RopeLeaf() {
    ...
    _S_free_string(..);
    ...
  }
};

...

template <class _CharT, class _Alloc>
inline /* note inline here */
void _Rope_RopeRep<_CharT,_Alloc>::_S_free_string(..)
{
  ...
}

Again, Sun compiler fails to link saying _S_free_string is
not defined. Probably, if an inline function is called in
another class before the definition of the inline function is
seen, then the compiler thinks that function has external
linkage. Is it a bug in Sun C++ or, should the definition
of _S_free_string be moved before the struct _Rope_RopeLeaf?


Thank you,
Saroj Mahapatra

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


[ 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              ]






Author: AllanW@my-dejanews.com
Date: 1998/07/27
Raw View
In article <6pfdos$v1n$1@nnrp1.dejanews.com>,
  saroj@my-dejanews.com wrote:
> Hi,
>
> I have a question about this piece of code and I'd like to
> know what the standard says.
>
> template <class _CharT, class _Alloc>
> class rope
> {
>   ....
>   friend rope<_CharT,_Alloc>   /* no inline here */
>   operator+ __STL_NULL_TMPL_ARGS (const rope<_CharT,_Alloc>& __left,
>                             const rope<_CharT,_Alloc>& __right);
>   ...
> };
>
> ...
>
> template <class _CharT, class _Alloc>
> inline   /* note the inline here */
> rope<_CharT,_Alloc>
> operator+ (const rope<_CharT,_Alloc>& __left,
>            const rope<_CharT,_Alloc>& __right)
> {
> ...
> }
>
> When used in a program, Sun compiler fails to link saying
> operator+(const rope&, const rope&) is not defined. Basically
> the absence of inline in the friend declaration makes it think
> that operator+ has external linkage and it does not notice
> inline later. Is it a bug in Sun C++ or should the 'inline'
> be added to the friend declaration?

Make sure that both the declaration and definition are visible
everywhere.  If these two code snippets are in different files,
the object file getting this error may have included the first
file but not the second one.

> Another question:
>
> template<class _CharT, class _Alloc>
> struct _Rope_RopeRep
> {
>   ....
>   static void _S_free_string(__GC_CONST _CharT*, size_t __len,
>                allocator_type __a);  /* no inline here */
>   ...
> };
>
> template<class _CharT, class _Alloc>
> struct _Rope_RopeLeaf
> {
>   ...
>   ~_Rope_RopeLeaf() {
>     ...
>     _S_free_string(..);
>     ...
>   }
> };
>
> ...
>
> template <class _CharT, class _Alloc>
> inline /* note inline here */
> void _Rope_RopeRep<_CharT,_Alloc>::_S_free_string(..)
> {
>   ...
> }
>
> Again, Sun compiler fails to link saying _S_free_string is
> not defined. Probably, if an inline function is called in
> another class before the definition of the inline function is
> seen, then the compiler thinks that function has external
> linkage. Is it a bug in Sun C++ or, should the definition
> of _S_free_string be moved before the struct _Rope_RopeLeaf?

Is _Rope_RopeLeaf derived from _Rope_RopeRep?  It isn't clear
how the call to _S_free_string is supposed to get to
a _Rope_RopeRep object.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
---
[ 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              ]