Bug 51617

Summary: won't compile template code with member and friend template operator funcs
Product: [Retired] Red Hat Raw Hide Reporter: j. alan eldridge <alane>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 1.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-10-01 23:38:56 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description j. alan eldridge 2001-08-13 03:34:48 UTC
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
//
 
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 23:38:56 UTC
It is indeed fixed in gcc3.