[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-08-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Marek Polacek  ---
Implemented in GCC 10.1.

[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-08-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

--- Comment #5 from Marek Polacek  ---
Author: mpolacek
Date: Mon Aug 19 13:59:13 2019
New Revision: 274671

URL: https://gcc.gnu.org/viewcvs?rev=274671=gcc=rev
Log:
PR c++/91264 - detect modifying const objects in constexpr.
* constexpr.c (modifying_const_object_error): New function.
(cxx_eval_call_expression): Set TREE_READONLY on a CONSTRUCTOR of
a const-qualified object after it's been fully constructed.
(modifying_const_object_p): New function.
(cxx_eval_store_expression): Detect modifying a const object
during constant expression evaluation.
(cxx_eval_increment_expression): Use a better location when building
up the store.
(cxx_eval_constant_expression) : Mark a constant
object's constructor TREE_READONLY.

* g++.dg/cpp1y/constexpr-tracking-const1.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const2.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const3.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const4.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const5.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const6.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const7.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const8.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const9.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const10.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const11.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const12.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const13.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const14.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const1.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const10.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const11.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const12.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const13.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const14.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const2.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const3.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const4.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const5.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const6.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const7.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const8.C
trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const9.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/constexpr.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-07-31 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

Marek Polacek  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #4 from Marek Polacek  ---
https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01914.html

[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-07-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

Marek Polacek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2019-07-27
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
 Ever confirmed|0   |1

[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-07-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

--- Comment #3 from Marek Polacek  ---
Another:

struct X {
  int j;
  constexpr X() : j(0) { }
};

struct Y {
  X x;
  constexpr Y() : x{} { }
};

constexpr void
g ()
{
  constexpr Y y{};
  Y *p = const_cast();
  p->x.j = 99;
}

static_assert((g(), 1), "");

I have a patch that handles all the tests in this PR so far.

[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-07-25 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

--- Comment #2 from Marek Polacek  ---
Another test:

constexpr void
f (int )
{
  r = 99;
}

constexpr int
f2 ()
{
  const int i = 0;
  f (const_cast(i));
  return i;
}

constexpr int i = f2 ();

[Bug c++/91264] modifying const-qual object in constexpr context not detected

2019-07-25 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91264

--- Comment #1 from Marek Polacek  ---
Similar for e.g.
  const_cast(i)++;