From 7073413404252602945
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,d53338cd62537f87,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-04-17 14:00:01 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!torn!news-out.cwix.com!newsfeed.cwix.com!newsfeed.icl.net!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: heapsma@lmtas.lmco.com (Mark Heaps)
Newsgroups: comp.std.c++
Subject: What does the standard say about Loki's ConversionHelper
Date: Wed, 17 Apr 2002 20:59:49 GMT
Organization: Lockheed Martin Corporation
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3cbdd850.75707781@news.mar.lmco.com>
Reply-To: mark.a.heaps@lmco.com
X-Trace: mail2news.demon.co.uk 1019077195 mail2news:12700 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Content-transfer-encoding: 7BIT
X-Newsreader: Forte Free Agent 1.21/32.243
Lines: 68
Xref: archiver1.google.com comp.std.c++:10676

My compiler rejects the following snippet from the Loki library:

template <class T, class U>
struct ConversionHelper {
  typedef char Small;
  struct Big { char dummy[2]; };
  static Small Test(U);
  static Big   Test(...);
  static T MakeT();
};

template <class T, class U>
struct Conversion {
  typedef ConversionHelper<T,U> H;
  enum { exists = sizeof(H::Test(H::MakeT())) == sizeof(H::Small) };
  enum { exists2Way = exists && Conversion<U, T>::exists };
  enum { sameType = false };
};

int main()
{
    return    Conversion<int, long>::exists +
        10 *  Conversion<int, long>::exists2Way +
        100 * Conversion<int, long>::sameType;
}

"ConversionHelper.cpp", line 13: error: operand of sizeof may not be a
function
    enum { exists = sizeof(H::Test(H::MakeT())) == sizeof(H::Small) };

The last of several exchanges with the compiler vendor, resulted in
this analysis:
--- Vendor analysis
 ...
In this case the sizeof operator indeed has an expression, but that
expression has an incomplete type. Regrettably, the compiler is not
very clear in its diagnostic messages. However, this is what's going
on.

 - when templates are involved, they are not scanned until the point
of instantiation - their tokens are only cached, and their members and
layout is not recorded into the symbol table. C++ works this way
because templates don't actually have to have code that compiles if
they are never instantiated

 - in the example given, the class 'Conversion' is referring to the
class 'Private::ConversionHelper' which hasn't been instantiated. When
a member of the latter class is looked up, none of its internal
information is known, so the expressions in the sizeof operator are
viewed as not having complete types.

So it is not that the compiler is overly strict - it is more
fundamental in the way that template instantiation should happens.
 ...
--- End of vendor analysis

So my questions are:
What paragraphs of the standard support (or refute) that analysis?
Is the code legal or illegal?
---
Mark Heaps

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



