[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-03-09 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #22 from Marek Polacek --- Author: mpolacek Date: Thu Mar 9 16:36:37 2017 New Revision: 246008 URL: https://gcc.gnu.org/viewcvs?rev=246008&root=gcc&view=rev Log: PR c++/79687 * init.c (constant_value_1): Break if the

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-24 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #21 from Marek Polacek --- Patch posted . Let's see how it pans out.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-24 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 Marek Polacek changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned a

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-24 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #20 from Marek Polacek --- Oh well. Anyway, this --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1973,7 +1973,8 @@ cp_fold_maybe_rvalue (tree x, bool rval) { x = cp_fold (x); if (rval && DECL_P (x) -

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-24 Thread reichelt at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #19 from Volker Reichelt --- No, that's again invalid. The second operand of .* or .-> must point to a valid class member, otherwise you'll get undefined behavior. The only way to achieve this in this class with a single member is to

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #18 from Marek Polacek --- An alternative, and hopefully still valid testcase: struct A { char c; }; int main() { static char A::* q; A a; return &(a.*q) - &a.c; }

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #17 from Marek Polacek --- I see, thanks for pointing that out.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread reichelt at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #16 from Volker Reichelt --- According to [expr.mptr.oper] the code in comment 15 has undefined behavior, because the second operand of ->* is the null-pointer-to-member-value.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #15 from Marek Polacek --- Slightly reduced original testcase: struct A { char c; }; int main() { static char A::* const q = nullptr; A a; return &(a.*q) - &a.c; }

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #14 from Marek Polacek --- Ah, I see cp_convert_to_pointer does 212 /* A NULL pointer-to-data-member is represented by -1, not by 213 zero. */ 214 tree val = (TYPE_PTRDATAMEM_P (type) 215 ?

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #13 from Marek Polacek --- Uh. (sizetype) q is folded to -1 in constant_value_1. DECL_INITIAL of "q" is -1, that's what build_zero_init_1 did: 177 else if (TYPE_PTR_OR_PTRMEM_P (type)) 178 init = fold (convert (type, nullptr

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #12 from Marek Polacek --- What's changed in r231197 is that previously we had return = (int) ((long int) ((char *) &a + (sizetype) q) - (long int) &a.c); but now return = (int) ((long int) ((char *) &a + 18446744073709551615) - (lo

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread reichelt at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #11 from Volker Reichelt --- The following testcase returns 1 for me since at least GCC 4.7. clang (3.2 - 4.0.0rc2), VS (2012, 2015) and ICC all return 0. struct A { char

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #10 from Marek Polacek --- Ok, so the Comment 4 testcase started to abort with r217814 and stopped with r229167.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #9 from Jonathan Wakely --- Looks valid to me.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 Richard Biener changed: What|Removed |Added Target Milestone|--- |5.5

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #8 from Marek Polacek --- Not sure, but clang++ accepts this without warning and the program returns 0.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #7 from Markus Trippelsdorf --- Well, the first question is: is this valid C++ code?

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #6 from Marek Polacek --- Duh, I can reproduce the abort with gcc-5 on my laptop, but not on another machine.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread reichelt at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #5 from Volker Reichelt --- The problems actually seem to be older. We experienced crashes already with GCC 4.8.2, but don't have a small testcase for this, yet.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #4 from Markus Trippelsdorf --- Hmm, I was using: struct A { char c; }; int main() { char A::*p = &A::c; static char A::*const q = p; A a; if (&(a.*q) - &a.c) __builtin_abort(); } and this triggers with gcc-5.

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 --- Comment #3 from Marek Polacek --- commit 69f54cf56ac077735cc599dc0db060143ba3713c Author: jason Date: Wed Dec 2 19:04:43 2015 + Introduce cp_fold_rvalue. * cp-gimplify.c (cp_fold_maybe_rvalue, cp_fold_rvalue):

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 Marek Polacek changed: What|Removed |Added CC||mpolacek at gcc dot gnu.org --- Comment

[Bug c++/79687] [5/6/7 Regression] Wrong code with pointer-to-member

2017-02-23 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79687 Markus Trippelsdorf changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed|