This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH to fix wrong-code with pointer-to-data-members (PR c++/79687)


On Fri, Feb 24, 2017 at 8:22 AM, Marek Polacek <polacek@redhat.com> wrote:
> I had an interesting time tracking down some of the problems with this code.
> Hopefully I've sussed out now how this stuff works.
>
> We've got
>
> struct A { char c; };
> char A::*p = &A::c;
> static char A::*const q = p;
> and then
> &(a.*q) - &a.c
> which should evaluate to 0.  Here "p" will be 0, that's the offset from the
> start of the struct to "c".  "q" is const-qualified and static and initialized
> with "p", so we get to cp_fold_maybe_rvalue -> decl_constant_value ->
> constant_value_1.  Now, NULL pointer-to-data-members are represented by -1, so
> that a null pointer is distinguishable from an offset of the first member of a
> struct (0).  So constant_value_1 looks at the DECL_INITIAL of "q", which is -1,
> a constant, we fold "q" to -1, and sadness ensues.  I believe the -1 value is
> only an internal representation and shouldn't be used like that.

Since q is initialized from p, it shouldn't have a DECL_INITIAL of -1;
that sounds like the bug.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]