delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/11/02/20:08:35

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <023701c16403$dfa81a60$6501a8c0@dns.rcn.net>
Reply-To: "Robert Allan Schwartz" <notbob AT tessellation DOT com>
From: "Robert Allan Schwartz" <notbob AT tessellation DOT com>
To: <cygwin AT cygwin DOT com>
Subject: g++ 2.95.3-5 - Templates bug?
Date: Fri, 2 Nov 2001 20:07:08 -0500
Organization: Tessellation Training
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700

I adapted some code from Andrei Alexandrescu's Loki class library:

// start of code:

#include <iostream>

using namespace std;

template <typename T, typename U>
class Conversion
{
public:
#ifdef ONE
template <typename T1, typename U1>
class ConversionHelper
{
public:
typedef char Small;
struct Big { char dummy[2]; };
static Big   Test(...);
static Small Test(U1);
static T1 MakeT();
};
        typedef ConversionHelper<T, U> H;
        enum { exists = sizeof(typename H::Small) ==
sizeof(H::Test(H::MakeT())) };
#endif
#ifdef TWO
typedef char Small;
struct Big { char dummy[2]; };
static Big   Test(...);
static Small Test(U);
static T MakeT();
        enum { exists = sizeof(            Small) == sizeof(   Test(  
MakeT())) };
#endif
        enum { exists2Way = exists && Conversion<U, T>::exists };
        enum { sameType = false };
};
    
template <typename T>
class Conversion<T, T>    
{
public:
    enum { exists = 1, exists2Way = 1,sameType = 1 };
};
    
int main()
{
    cout << Conversion<double, int>::exists;

return 0;
}

// end of code

I'm using g++ version 2.95.3-5.

If I compile -DONE, it compiles and executes OK.

If I compile -DTWO, it gets the following errors:

andrei.cpp: In instantiation of `Conversion<double,int>':
andrei.cpp:44:   instantiated from here
andrei.cpp:44: invalid use of undefined type `class
Conversion<double,int>'
andrei.cpp:33: forward declaration of `class Conversion<double,int>'
andrei.cpp:44: invalid use of undefined type `class
Conversion<double,int>'
andrei.cpp:33: forward declaration of `class Conversion<double,int>'
andrei.cpp: In instantiation of `Conversion<int,double>':
andrei.cpp:44:   instantiated from `Conversion<double,int>'
andrei.cpp:44:   instantiated from here
andrei.cpp:44: invalid use of undefined type `class
Conversion<int,double>'
andrei.cpp:33: forward declaration of `class Conversion<int,double>'
andrei.cpp:44: invalid use of undefined type `class
Conversion<int,double>'
andrei.cpp:33: forward declaration of `class Conversion<int,double>'

I don't understand why replacing the ConversionHelper with its members
causes the errors.

Is this a bug?

Robert Schwartz



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019