public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/6327: g++ problems where partial specializing nested templates
@ 2002-04-16 18:51 rodrigc
  0 siblings, 0 replies; 2+ messages in thread
From: rodrigc @ 2002-04-16 18:51 UTC (permalink / raw)
  To: cuni, gcc-bugs, gcc-prs, nobody

Synopsis: g++ problems where partial specializing nested templates

State-Changed-From-To: open->closed
State-Changed-By: rodrigc
State-Changed-When: Tue Apr 16 18:51:13 2002
State-Changed-Why:
    Compiles OK with gcc 3.0.4.
    
    With gcc 3.1 (prerelease) there are some warnings, but
    it still compiles:
    a.cc:18: warning: `typename Array_traits<T>::Rebind<U>::Type' is implicitly a
       typename
    a.cc:18: warning: implicit typename is deprecated, please see the documentation
       for details
    

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6327


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/6327: g++ problems where partial specializing nested templates
@ 2002-04-16 10:16 cuni
  0 siblings, 0 replies; 2+ messages in thread
From: cuni @ 2002-04-16 10:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6327
>Category:       c++
>Synopsis:       g++ problems where partial specializing nested templates
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 16 10:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     g++
>Release:        Thread model: single - gcc version 3.0
>Organization:
>Environment:
Mandrake 8.0 on AMD Athlon 800
>Description:
It seems that the compiler doesn't use correctly partial specialization of a nested template, even if it produce correct code when template are not nested.
>How-To-Repeat:
#include <typeinfo>
#include <iostream>

// generic template
template<class T>
struct Array_traits
{
  template<class U>
  struct Rebind
  {
    typedef U Type;
  };
};

// partial specialization for arrays
template<class T, int N>
struct Array_traits<T[N]>
{
  template<class U>
  struct Rebind
  {
    typedef Array_traits<T>::Rebind<U>::Type Type[N];
  };
};

int main()
{
  typedef int array_of_int[10][20][30];
  Array_traits<array_of_int>::Rebind<float>::Type array_of_float;

  // it prints out A10_A20_A30_i
  std::cout << typeid(array_of_int).name() << std::endl;

  // it should print A10_A20_A30_f, but it prints A10_f
  std::cout << typeid(array_of_float).name() << std::endl;
}
>Fix:
Here is a work-around that doesn't use nested templates:

// generic template
template<class T, class U> 
struct Array_rebind
{
  typedef U Type;
};

// partial specialization
template<class T, int N, class U>
struct Array_rebind<T[N], U>
{
  typedef Array_rebind<T,U>::Type Type[N];
};
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-17  1:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-16 18:51 c++/6327: g++ problems where partial specializing nested templates rodrigc
  -- strict thread matches above, loose matches on Subject: below --
2002-04-16 10:16 cuni

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).