Boost logo

Boost :

From: Mat Marcus (mat-boost_at_[hidden])
Date: 2005-08-17 04:05:41

Hash: SHA1


On 8/16/05, Thomas Witt <witt_at_[hidden]> wrote:

> I can't say whether that is your problem, but code like this is
> potentially dangerous. It'll break whenever you happen to "suck" in a
> use of operator~ on an unnamed enum. And yes it tends to generate
> error messages. Looking at the errors the unknown type in the is_enum
> instantiation looks suspicious to me.
> I only have apples gcc 4 currently. A slightly modified example gives
> enum { foo, bar };
> template <typename EnumType>
> typename boost::enable_if<boost::is_enum<EnumType>, EnumType>::type
> operator ~ (EnumType a);
> int main()
> {
> int i = ~bar;
> std::stringstream t;
> }
> mat.cpp: In function 'int main()':
> mat.cpp:14: error: '<anonymous enum>' is/uses anonymous type
> mat.cpp:14: error: trying to instantiate 'template<class T> struct
> boost::is_enum'
> Thomas

Thanks for sending this fascinating example. After doing a bit of my
own exploration with gcc 4.0 I must agree with you. If I understand the
ramifications correctly, if gcc 4.0 correctly disallows instantiating
templates upon unnamed enum types, then SFINAE cannot be safely used
for operators that may also happen to exist for (anonymous) enums. In
the example above, even if we replace is_enum with a more restricted
metafunction, the problem will not go away, since any instantiation
would seem to be prohibited. Worse still, though it is easy enough to
avoid calling the operator with an anonymous enum, I must also avoid
files that might use operators on other unrelated anonymous enums, lest
the compiler try to illegally instantiate the metafunction.

So the big question is, "Is there no known way of safely testing
whether a type is an anonymous enum?"


Version: PGP Desktop 9.0.2 (Build 2424)


Boost list run by bdawes at, gregod at, cpdaniel at, john at