Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2003-12-09 14:33:04


On Tue, 09 Dec 2003 19:41:13 +0100, Rani Sharoni wrote:

> Daniel Frey wrote:
>> Rani Sharoni wrote:
>>> I accidentally encounter some bug in EDG (latest) that is exploitable
>>> for implementing is_incomplete. I personally despise this ODR rebel
>>> but I suspect that some really like it.
>>
>> I was thinking about something similar while fixing checked_delete, but
>> refrained from it as violating the ODR seemed to dangerous to me. Check
>> the "feature" of some compilers to set the sizeof(T) to 0 for
>> incomplete types T. Maybe it works on more compilers than the bug you
>> found currently, since some vendors think it's a feature :o)
>
> I suspect that except for EDG no compiler is compliant enough to allow
> such abuse :)

Hm, either I midread what you wrote above or you misread what I wrote
above :) Let's clarify my point with some code:

--- File t.h ---

template< typename T > struct is_complete
{
    enum { value = sizeof(T) > 0 };
};

--- File t.cc ---

#include <iostream>
using namespace std;

#include <t.h> // Important: don't use "t.h"!

class X;
class Y {};

int main()
{
    cout << is_complete< void >::value << endl;
    cout << is_complete< void const >::value << endl;

    cout << is_complete< int >::value << endl;
    cout << is_complete< int const >::value << endl;
    cout << is_complete< int volatile >::value << endl;
    cout << is_complete< int const volatile >::value << endl;

    cout << is_complete< X >::value << endl;
    cout << is_complete< X const >::value << endl;
    cout << is_complete< X volatile >::value << endl;
    cout << is_complete< X const volatile >::value << endl;
    cout << is_complete< X[] >::value << endl;
    cout << is_complete< X[ 2 ] >::value << endl;

    cout << is_complete< Y >::value << endl;
    cout << is_complete< Y const >::value << endl;
    cout << is_complete< Y volatile >::value << endl;
    cout << is_complete< Y const volatile >::value << endl;
    cout << is_complete< Y[] >::value << endl;
    cout << is_complete< Y[ 2 ] >::value << endl;
}

--- Compiled with the Intel 7.1 ---

icc -ansi -O2 -I. t.cc

This does what you expect but with a much easier implementation and you
might want to check what other compilers say about it, e.g. CW

Regards, Daniel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk