public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/6023: Valid template code does not compile
@ 2002-03-21  2:06 Kretschel Klaus
  0 siblings, 0 replies; only message in thread
From: Kretschel Klaus @ 2002-03-21  2:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6023
>Category:       c++
>Synopsis:       Valid template code does not compile
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 21 02:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Klaus Kretschel
>Release:        3.0.4
>Organization:
DLR 
>Environment:
System: Linux darwin 2.4.4-64GB-SMP #1 SMP Wed May 16 01:20:45 GMT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure 
>Description:
The call h->do_calc from Otto::calc in test program below gives
              the parse error

              temp_test.cc: In member function `T Otto<T>::calc(VEC)':
              temp_test.cc:35: parse error before `;' token

              while the same syntax is correct when called from Hugo::calc.

              I cannot rule out that this might be covered by
	      the missing feature "Two stage lookup in templates
	      is not implemented" but I don't think so.

              Compiler call was "g++ -c -Wall temp_test.cc".

	
>How-To-Repeat:
Test program temp_test.ii (the "vektor" struct can as
                well be replaced by vector; it was only introduced
                to avoid lots of preprocessor output):

# 1 "temp_test.cc"
template<class V> struct vektor
{
  V a;
  vektor(V v) : a(v) {}
};

template<class T> struct Otto;

template<class T> struct Hugo
{
  template<class VEC>
  T calc(VEC x) {
    T tmp;
    tmp = this->do_calc<VEC>(x);
    return tmp;
  }

  template<class VEC>
  T do_calc(const typename Otto<T>::MyTraits<T, VEC>::T2& x)
  { return x.a; }
};

template<class T> struct Otto
{
  template<class T0, typename T1> struct MyTraits;

  template<class T0> struct MyTraits<T0, vektor<T0> >
  { typedef vektor<T0> T2; };

  template<class VEC>
  T calc(VEC x) {
    Hugo<T>* h;
    T tmp;
    tmp = h->calc<VEC>(x);
    tmp = h->do_calc<VEC>(x);
    return tmp;
  }
};

int main()
{
  vektor<char> c('X');
  Otto<char> otto;
  otto.calc(c);
}

	
>Fix:
Have an intermediate method that calls method from inside class
        (like "Hugo::calc" in test program). Possible but very unsatifying
        because of redundant code.
	
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-03-21 10:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-21  2:06 c++/6023: Valid template code does not compile Kretschel Klaus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).