https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

            Bug ID: 100209
           Summary: multiple inheritance with crtp pattern fails on
                    sequentioal member access
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: autumn.rain at mail dot ru
  Target Milestone: ---

If multiple inheritance is used with CRTP pattern in a constexpr context,
resulting class is failed to create.
When deriving AB from a single class (also with mani accessors) the constexpr
context is working well.
The error is reproduced on gcc since 6.1.x on any platform.


D:\>D:\0W\00Tools\2GCC_10.2_2020q4\bin\arm-none-eabi-g++ -Wall D:\Test.cpp
D:\Test.cpp:26:60: error: '*(const __ab_t*)(&(&
__ab_t().__ab_t::<anonymous>.__a
_t<__ab_t>::SetA(100))->__ab_t::<anonymous>.__b_t<__ab_t>::SetB(10))' is not a
c
onstant expression
   26 | static constexpr const auto AB = __ab_t().SetA(100).SetB(10);
      |                                                            ^

gcc version
10.2.1 

template<typename TDERIVED>
struct __a_t
{
       unsigned char A = 0;
       constexpr TDERIVED & SetA(const unsigned char & value) { A = value;  
return *static_cast<TDERIVED *>(this); }

       constexpr __a_t() {}
};

template<typename TDERIVED>
struct __b_t
{
       unsigned char B = 0;
       constexpr TDERIVED & SetB(const unsigned char & value) { B = value;
return *static_cast<TDERIVED *>(this); }

       constexpr __b_t() {}
};

class __ab_t: public __a_t<__ab_t>, public __b_t<__ab_t>
{
    public:
        constexpr __ab_t(){}

};

static constexpr const auto AB = __ab_t().SetA(100).SetB(10);

int A = 0;

int main()
{
    A = AB.A;
}

How-To-Repeat:
Compile the attached code

Reply via email to