
[snip]
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 weird 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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thomas, On 8/16/05, Thomas Witt <witt@acm.org> wrote: this:
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?" Thanks, Mat -----BEGIN PGP SIGNATURE----- Version: PGP Desktop 9.0.2 (Build 2424) iQA/AwUBQwL96RIZBaoznf65EQKf6wCcDyhiiRlQBMQ5NBISeTiQ0rnVEuwAn1y6 D54sfcwOgIvouUhH6QWtzLgv =f75H -----END PGP SIGNATURE-----