I ran into an issue while overloading friend bitwise operator with template parameters for nested enums.
Originally I ran into the issue with proprietary embedded C++ compiler. After that I tried gcc, clang and MSVC and got exactly the same failure. Except, any GCC version prior to 5.0 that I have tried is able to compile example code. Choice of the C++ standard with any compiler does not seem to make any difference.
Here is an example:
struct Complex
{
struct Nested1
{
enum ENUM
{
Value1_1,
Value1_2
};
};
struct Nested2
{
enum ENUM
{
Value2_1,
Value2_2
};
};
template<typename EnumL, typename EnumR>
friend Complex operator|(const EnumL dummyL, const EnumR dummyR)
{
Complex dummyComplex;
return dummyComplex;
}
};
int main()
{
Complex complex = Complex::Nested1::Value1_1 | Complex::Nested2::Value2_2;
}
Compiler does not see operator |. Code compiles if I move operator overloading just below the structure definition. Although it is not a friend function anymore.
However, a little different code example compiles without any issues.
struct Complex
{
enum ENUM1
{
Value1_1,
Value1_2
};
enum ENUM2
{
Value2_1,
Value2_2
};
template<typename EnumL, typename EnumR>
friend Complex operator|(const EnumL dummyL, const EnumR dummyR)
{
Complex dummyComplex;
return dummyComplex;
}
};
int main()
{
Complex complex = Complex::Value1_1 | Complex::Value2_2;
}
What am I missing here?