🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3397

template instantiation/parsing question

#3397
From: Damon Lipparelli
Date: Thu, 22 Feb 1996 14:08
70 lines
2442 bytes
I'm in the process of porting some older C++ code to several newer
compilers.  The newer compilers (Visual C++ 4.0, G++ 2.7.2, and others) are
having problems with template constructs that have compiled for years under
our current compiler (Sun's SPARCworks 4.0.1).  I've been fighting my way
through the DWP, but I haven't been able to tell if the problematic code
_should_ work or not.

In short, I think the problem comes from wrapping a declared template type
around a forward referenced class type.  I've included a code snippet that
I think demonstrates the problem.

--- Cut Here ---
class base
{
public:
};

class tmpl_base
{
public:
  tmpl_base(void);
  tmpl_base(base& b);
private:
  base& b_;
};

template<class T>
class tmpl : public tmpl_base
{
public:
  tmpl(void)
    {}
  tmpl(T& t)
      : tmpl_base(t)
    {}
};

class foo;

class bar
{
public:
  bar(void);
private:
  tmpl<foo> foo_;
};
--- Cut Here ---

The Sun compiler accepts this without a complaint.  All of the other
compilers that I've tried compiling this under complain about the
"tmpl<foo> foo_;" in the declaration of "class bar".  If I replace this
line with "tmpl<foo>& foo_;", it compiles on _all_ of the compilers.

Does this make sense?  Is the Sun compiler out of date with respect to
instantiation rules?  Is is "undefined" as to how this should work?

Thanks for any info,
Damon Lipparelli
(lipp@primuscorp.com)

---

LBJ, LBJ, how many JOKES did you tell today??!
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Technical Details
Message-ID: <wi20noxzu9.fsf@zhora.symbologic.com>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back

Show Full Headers
Complete Article Headers
From: lipp@zhora.symbologic.com (Damon Lipparelli)
Message-ID: <wi20noxzu9.fsf@zhora.symbologic.com>
X-Original-Date: 21 Feb 1996 11:06:54 -0800
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 22 Feb 96 14:08:27 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: template instantiation/parsing question
Organization: Symbologic Corporation
Reply-To: Damon Lipparelli <lipp@primuscorp.com>
X-Newsreader: Gnus v5.0.15
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMSx4+uEDnX0m9pzZAQEORQGAoA5DP14wrdWwQDB/ZYmw1ej5jp54xlXQ
 tdzW8bOtmp5fdBaIAG5kf3pigkMX9vcL
 =CFpt