Bug 51617 - won't compile template code with member and friend template operator funcs
Summary: won't compile template code with member and friend template operator funcs
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc (Show other bugs)
(Show other bugs)
Version: 1.0
Hardware: i386 Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-08-13 03:34 UTC by j. alan eldridge
Modified: 2007-04-18 16:35 UTC (History)
0 users

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: ---


Attachments (Terms of Use)

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@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 23:38:56 UTC
It is indeed fixed in gcc3.


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