|
Boost : |
Subject: Re: [boost] [type_traits] is_complete<T> possible realization
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2012-11-09 12:23:27
On Fri, Nov 9, 2012 at 12:18 PM, Matt Calabrese <rivorus_at_[hidden]> wrote:
> While the above code might seem contrived, it could definitely happen when
> dealing with forward declarations of classes. Because of this, I'd
> recommend in general only using a completeness checker with something like
> a static_assert anyway, forcing compilation to fail when you don't get the
> result that you'd expect, otherwise you have to be extremely careful.
>
In case it wasn't clear, I was implying in the code sample that the
template was instantiated with foo in both translation units (forgot to
show that). Since in one translation unit foo is incomplete and in the
other it is complete, you could potentially violate ODR by producing a
different definition for you_code< foo > in each translation unit. Of
course, you could get around this by using the ODR trick from the
completeness checker (putting the call to the metafunction in a default
argument to the template), but then you're effectively pushing out the
problem to a higher-level. In order to be completely safe, you'd have to
propagate the checking all the way out to the top level instantiation.
-- -Matt Calabrese
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk