PR c++/91264 - detect modifying const objects in constexpr.
authorMarek Polacek <polacek@redhat.com>
Mon, 19 Aug 2019 13:59:13 +0000 (13:59 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 19 Aug 2019 13:59:13 +0000 (13:59 +0000)
commit04e1749c557a5df14f8528efa451bb0e93afea80
treed3254c67f6ed344600c62297817d2c44b595a9e3
parent5a9ea4fff4554d9dc0966e8f2598a01602df03cf
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) <case DECL_EXPR>: 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.

From-SVN: r274671
17 files changed:
gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const14.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const9.C [new file with mode: 0644]