Bug 51617 - won't compile template code with member and friend template operator funcs
won't compile template code with member and friend template operator funcs
Status: CLOSED CURRENTRELEASE
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc (Show other bugs)
1.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-08-12 23:34 EDT by j. alan eldridge
Modified: 2007-04-18 12:35 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-01 19:38:56 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description j. alan eldridge 2001-08-12 23:34:48 EDT
Description of Problem:

In all probability, this affects RH7.x, too. The net effect is that I
cannot compile the speech_tools package from the Festival TTS synthesizer.
(Oh, I'll get it to compile, all right, but not without some major hackery
of a nature not find for children under 18.)

See contrived example code.

// -*-C++-*-
//
// tt.cc
// Copyright (c) 2001 Alan Eldridge
//
// $Id$
//
// 2001-08-11 alane@geeksrus.net
//
 
template<class T, class U> class Tmpl;
 
template<class T, class U>
bool operator==(const Tmpl<T, U> &lhs, const Tmpl<T, U> &rhs);
 
template<class T, class U>
class Tmpl {
private:
  T *pt_;
public:
  Tmpl():
    pt_(0) {
  }
#ifdef WONT_COMPILE
  bool operator==(const T* pt) const {
    return pt_ == pt;
  }
#endif // WONT_COMPILE
  friend bool operator==<>(const Tmpl<T,U> &, const Tmpl<T, U> &);
};
 
template<class T, class U>
bool operator==(const Tmpl<T, U> &lhs, const Tmpl<T, U> &rhs) {
  return lhs.pt_ == rhs.pt_;
}
 
Tmpl<int,char> tint;

// EOF

See code compile. Compile, code, compile.

[alane@wwweasel alane]$ gcc -c tt.cc
[alane@wwweasel alane]$ gcc -DWONT_COMPILE=1 tt.cc
tt.cc: In instantiation of `Tmpl<int, char>':
tt.cc:43:   instantiated from here
tt.cc:35: invalid use of undefined type `class Tmpl<int, char>'
tt.cc:23: forward declaration of `class Tmpl<int, char>'
[alane@wwweasel alane]$

Oops. Bad compiler. Code won't compile.

This bug is not present in GCC3. As long as festival doesn't link against
anything else but glibc and libstdc++ then it's probably safe for me to
build using GCC3. 

Otherwise, for each of the six or seven classes with this problem, I'll
have to devise member accessor functions to get at the parts the operator
functions need, then rewrite them as non-friends. I'd convert them to
member functions, if they were all like == and !=, but unfortunately,
there's an operator<<(ostream&,thing&) thrown in there that squashes that plan.
Comment 1 Richard Henderson 2004-10-01 19:38:56 EDT
It is indeed fixed in gcc3.

Note You need to log in before you can comment on or make changes to this bug.