public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access
@ 2021-04-22 12:48 autumn.rain at mail dot ru
  2021-04-22 13:14 ` [Bug c++/100209] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: autumn.rain at mail dot ru @ 2021-04-22 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
@ 2021-04-22 13:14 ` rguenth at gcc dot gnu.org
  2021-04-23  2:51 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-22 13:14 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
clang accepts it

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
  2021-04-22 13:14 ` [Bug c++/100209] " rguenth at gcc dot gnu.org
@ 2021-04-23  2:51 ` ppalka at gcc dot gnu.org
  2021-04-23  4:28 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-23  2:51 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
   Last reconfirmed|                            |2021-04-23
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed.  A bit more reduced:

struct A { int a = 0; };

template <class Derived>
struct B
{
  int b = 0;
  constexpr Derived f(int n) {
    return *static_cast<Derived*>(this);
  }
};

struct C : A, B<C> { };

constexpr C c = C().f(10);


100209.C:14:22:   in ‘constexpr’ expansion of ‘C().C::<anonymous>.B<C>::f(10)’
100209.C:14:25: error: ‘*(const C*)((C*)(((B<C>*)this) + -4))’ is not a
constant expression
   14 | constexpr C c = C().f(10);
      |                         ^

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
  2021-04-22 13:14 ` [Bug c++/100209] " rguenth at gcc dot gnu.org
  2021-04-23  2:51 ` ppalka at gcc dot gnu.org
@ 2021-04-23  4:28 ` ppalka at gcc dot gnu.org
  2021-04-23  4:29 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-23  4:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
During cxx_eval_indirect_ref for

  *(const struct C &) (const struct C *) (struct C *) ((struct B *) this + -4);

constant evaluation of the pointee yields

  &D.2217.D.2106 + -4

where D.2217 is a temporary of type C and D.2106 is the FIELD_DECL for the base
B<C>.  The problem seems to be that cxx_fold_indirect_ref doesn't know how to
fold this second expression to just

  &D.2217

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
                   ` (2 preceding siblings ...)
  2021-04-23  4:28 ` ppalka at gcc dot gnu.org
@ 2021-04-23  4:29 ` ppalka at gcc dot gnu.org
  2021-04-26 21:31 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-23  4:29 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
                   ` (3 preceding siblings ...)
  2021-04-23  4:29 ` ppalka at gcc dot gnu.org
@ 2021-04-26 21:31 ` cvs-commit at gcc dot gnu.org
  2021-04-28  2:34 ` ppalka at gcc dot gnu.org
  2021-11-06 23:40 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-26 21:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:0120cd9382728fdc99d4cfdcb72cd0f55aca2ce3

commit r12-136-g0120cd9382728fdc99d4cfdcb72cd0f55aca2ce3
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Apr 26 17:30:39 2021 -0400

    c++: constexpr pointer indirection with negative offset [PR100209]

    During constexpr evaluation, a base-to-derived conversion may yield an
    expression like (Derived*)(&D.2217.D.2106 p+ -4) where D.2217 is the
    derived object and D.2106 is the base.  But cxx_fold_indirect_ref
    doesn't know how to resolve an INDIRECT_REF thereof to just D.2217,
    because it doesn't handle POINTER_PLUS_EXPR of a COMPONENT_REF with
    negative offset well: when the offset N is positive, it knows that
    '&x p+ N' is equivalent to '&x.f p+ (N - bytepos(f))', but it doesn't
    know about the reverse transformation, that '&x.f p+ N' is equivalent
    to '&x p+ (N + bytepos(f))' when N is negative, which is important for
    resolving such base-to-derived conversions and for accessing subobjects
    backwards.  This patch teaches cxx_fold_indirect_ref this reverse
    transformation.

    gcc/cp/ChangeLog:

            PR c++/100209
            * constexpr.c (cxx_fold_indirect_ref): Try to canonicalize the
            object/offset pair for a POINTER_PLUS_EXPR of a COMPONENT_REF
            with a negative offset into one whose offset is nonnegative
            before calling cxx_fold_indirect_ref_1.

    gcc/testsuite/ChangeLog:

            PR c++/100209
            * g++.dg/cpp1y/constexpr-base1.C: New test.
            * g++.dg/cpp1y/constexpr-ptrsub1.C: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
                   ` (4 preceding siblings ...)
  2021-04-26 21:31 ` cvs-commit at gcc dot gnu.org
@ 2021-04-28  2:34 ` ppalka at gcc dot gnu.org
  2021-11-06 23:40 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-28  2:34 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |12.0

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12, thanks for the bug report.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access
  2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
                   ` (5 preceding siblings ...)
  2021-04-28  2:34 ` ppalka at gcc dot gnu.org
@ 2021-11-06 23:40 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-06 23:40 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steven.vanderschoot@nextlev
                   |                            |el-electronics.com

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 97752 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-06 23:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 12:48 [Bug c++/100209] New: multiple inheritance with crtp pattern fails on sequentioal member access autumn.rain at mail dot ru
2021-04-22 13:14 ` [Bug c++/100209] " rguenth at gcc dot gnu.org
2021-04-23  2:51 ` ppalka at gcc dot gnu.org
2021-04-23  4:28 ` ppalka at gcc dot gnu.org
2021-04-23  4:29 ` ppalka at gcc dot gnu.org
2021-04-26 21:31 ` cvs-commit at gcc dot gnu.org
2021-04-28  2:34 ` ppalka at gcc dot gnu.org
2021-11-06 23:40 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).