[Bug c++/70172] incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70172 Martin Sebor changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #6 from Martin Sebor --- Fixed by r234698.
[Bug c++/70172] incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70172 --- Comment #5 from Martin Sebor --- Author: msebor Date: Sat Apr 2 17:14:48 2016 New Revision: 234698 URL: https://gcc.gnu.org/viewcvs?rev=234698=gcc=rev Log: PR c++/67376 - [5/6 regression] Comparison with pointer to past-the-end of array fails inside constant expression PR c++/70170 - [6 regression] bogus not a constant expression error comparing pointer to array to null PR c++/70172 - incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization PR c++/70228 - insufficient detail in diagnostics for a constexpr out of bounds array subscript gcc/testsuite/ChangeLog: 2016-04-02 Martin SeborPR c++/67376 PR c++/70170 PR c++/70172 PR c++/70228 * g++.dg/cpp0x/constexpr-array-ptr10.C: New test. * g++.dg/cpp0x/constexpr-array-ptr9.C: New test. * g++.dg/cpp0x/constexpr-nullptr-1.C: New test. * g++.dg/cpp0x/constexpr-array5.C: Adjust text of expected diagnostic. * g++.dg/cpp0x/constexpr-string.C: Same. * g++.dg/cpp0x/constexpr-wstring2.C: Same. * g++.dg/cpp0x/pr65398.C: Same. * g++.dg/ext/constexpr-vla1.C: Same. * g++.dg/ext/constexpr-vla2.C: Same. * g++.dg/ext/constexpr-vla3.C: Same. * g++.dg/ubsan/pr63956.C: Same. gcc/cp/ChangeLog: 2016-04-02 Martin Sebor PR c++/67376 PR c++/70170 PR c++/70172 PR c++/70228 * constexpr.c (diag_array_subscript): New function. (cxx_eval_array_reference): Detect out of bounds array indices. gcc/ChangeLog: 2016-04-02 Martin Sebor PR c++/67376 * fold-const.c (maybe_nonzero_address): New function. (fold_comparison): Call it. Fold equality and relational expressions involving null pointers. (tree_single_nonzero_warnv_p): Call maybe_nonzero_address. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr10.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr9.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-nullptr-1.C Modified: trunk/gcc/ChangeLog trunk/gcc/cp/ChangeLog trunk/gcc/cp/constexpr.c trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-string.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-wstring2.C trunk/gcc/testsuite/g++.dg/cpp0x/pr65398.C trunk/gcc/testsuite/g++.dg/ext/constexpr-vla1.C trunk/gcc/testsuite/g++.dg/ext/constexpr-vla2.C trunk/gcc/testsuite/g++.dg/ext/constexpr-vla3.C trunk/gcc/testsuite/g++.dg/ubsan/pr63956.C
[Bug c++/70172] incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70172 --- Comment #4 from Martin Sebor --- Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00796.html
[Bug c++/70172] incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70172 Martin Sebor changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2016-03-11 Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #3 from Martin Sebor --- My patch for bug 67376 handles this case as well.
[Bug c++/70172] incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70172 --- Comment #2 from Martin Sebor --- I should add that the bogus "reinterpret_cast" error goes away when the address of a non-array member is used instead, as in the test case below, even though this modified test case is also invalid for the same reason (using a null pointer). Failing to diagnose the modified test case is the subject of bug 60760. $ cat z.c && /home/msebor/build/gcc-trunk-svn/gcc/xgcc -B/home/msebor/build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -o/dev/null -xc++ z.c struct S { int a, b; } s; constexpr S *p = (S*)0; constexpr const int *q = >b;
[Bug c++/70172] incorrect reinterpret_cast from integer to pointer error on invalid constexpr initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70172 Martin Sebor changed: What|Removed |Added Keywords||diagnostic Blocks||55004 Known to fail||6.0 --- Comment #1 from Martin Sebor --- I would normally make the Severity of a bug in the text of a diagnostic minor but this one seems like it's more than a poorly phrased diagnostic. The code that triggers the error is in the potential_constant_expression_1() function in constexp.c: case NOP_EXPR: case CONVERT_EXPR: case VIEW_CONVERT_EXPR: /* -- a reinterpret_cast. FIXME not implemented, and this rule may change to something more specific to type-punning (DR 1312). */ { tree from = TREE_OPERAND (t, 0); if (POINTER_TYPE_P (TREE_TYPE (t)) && TREE_CODE (from) == INTEGER_CST && !integer_zerop (from)) { if (flags & tf_error) error_at (EXPR_LOC_OR_LOC (t, input_location), "reinterpret_cast from integer to pointer"); return false; } return (RECUR (from, TREE_CODE (t) != VIEW_CONVERT_EXPR)); } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004 [Bug 55004] [meta-bug] constexpr issues