[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-11-06 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

Patrick Palka  changed:

   What|Removed |Added

 CC||steven.vanderschoot@nextlev
   ||el-electronics.com

--- Comment #6 from Patrick Palka  ---
*** Bug 97752 has been marked as a duplicate of this bug. ***

[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-04-27 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

Patrick Palka  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |12.0

--- Comment #5 from Patrick Palka  ---
Fixed for GCC 12, thanks for the bug report.

[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-04-26 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Patrick Palka :

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

commit r12-136-g0120cd9382728fdc99d4cfdcb72cd0f55aca2ce3
Author: Patrick Palka 
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*)( 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
' p+ N' is equivalent to ' p+ (N - bytepos(f))', but it doesn't
know about the reverse transformation, that ' p+ N' is equivalent
to ' 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.

[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-04-22 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

Patrick Palka  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |ppalka at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-04-22 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

--- Comment #3 from Patrick Palka  ---
During cxx_eval_indirect_ref for

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

constant evaluation of the pointee yields

   + -4

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

  

[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-04-22 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

Patrick Palka  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  ---
Confirmed.  A bit more reduced:

struct A { int a = 0; };

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

struct C : A, B { };

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


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

[Bug c++/100209] multiple inheritance with crtp pattern fails on sequentioal member access

2021-04-22 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100209

Richard Biener  changed:

   What|Removed |Added

   Keywords||rejects-valid

--- Comment #1 from Richard Biener  ---
clang accepts it