Undefined A link in an inline function resolved using unary +

I have a weird gcc 4.7 issue with C ++ 11 enabled:

When I want to compile this:

constexpr unsigned int getDim(const int e){
        return (e==1)?  A::Set::Dimension :
            (
              (e==2)? B::Set::Dimension :

                (
                    (e==3)? C::Set::Dimension :
                    (
                       +D::Set::Dimension

                    )
                )
            );
 }

where for each structure a A,B,C,Dtypedef is defined for Set, where the associated Set has an int Dimension, for example

struct SetOne{
   static const int Dimension = 1;
}

struct A{
   typedef SetOne Set;
}

If I do not use unary +infront from D::Set::Dimension, the linker cannot complain about undefined references to SetOne :: Dimension.

This is the same problem as: Undefined reference to a static member of a class

I can’t give MWE since the problem disappeared for a simple example with a single .cpp file.? (but all definitions for A, B, C, D are in one header file)

Does anyone know what could go wrong? This is unintuitiv :-)

2: : +D::Set::Dimension 0, , A::Set::Dimension ?

+4
1

, , lvalue, odr . , , odr, , ( ).

, +?

+ odr- , rvalue, rvalue. , rvalue, r-. , + lvalue-to-rale , , odr.

: + D:: Set:: Dimension 0, fine

, 0 - r, , +, .

+8

Source: https://habr.com/ru/post/1531026/


All Articles