c++/5260: g++ rejects references to typedef in template parameter

cchen@digiMine.com cchen@digiMine.com
Wed Jan 2 13:06:00 GMT 2002


>Number:         5260
>Category:       c++
>Synopsis:       g++ rejects references to typedef in template parameter
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 02 13:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Cheng Che Chen
>Release:        3.0.x
>Organization:
>Environment:
RedHat 7.2
>Description:
I have a templatized function which references a typedef
in a template parameter.  g++ does not like that reference
to the typedef.
>How-To-Repeat:
g++ gcctest.cpp
>Fix:
I don't see how to get around the problem.
Sometimes you simply have to reference a typedef
inside a class.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="gcctest.cpp"
Content-Disposition: inline; filename="gcctest.cpp"

#include <cstdio>

struct HLP {
  typedef unsigned KeyType;
  KeyType Get(const double x) const { return ((KeyType) x); }
};

template <class H>
double sum(const unsigned n, const double v[], H &h)
{
#if (1)
  // This doesn't compile under g++.
  H::KeyType s = 0;
#else
  // workaround to allow me to check that everything else compiles
  unsigned s = 0;
#endif
  for (unsigned i=0; i<n; ++i) { s += h.Get(v[i]); }
  return ((double) s);
}

int main(int argc, char *argv[])
{
  const unsigned n = 5;
  const double v[n] = { 0.0, 1.0, 2.0, 3.0, 4.0 };
  HLP h;
  const double s = sum<HLP>(n, v, h);
  printf("%f\n", s);
  return (0);
}



More information about the Gcc-bugs mailing list