]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: small contracts fixes
authorJason Merrill <jason@redhat.com>
Wed, 30 Nov 2022 19:22:03 +0000 (14:22 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 1 Dec 2022 03:46:05 +0000 (22:46 -0500)
The first is an actual bug: remove_contract_attributes was only keeping one
attribute.  The second just helps flow analysis in optimizers and static
analyzers.

gcc/cp/ChangeLog:

* contracts.cc (remove_contract_attributes): Actually prepend
to the list.
* pt.cc (tsubst_contract): Only look for a postcondition if type is
nonnull.

gcc/cp/contracts.cc
gcc/cp/pt.cc

index a90970167686ba8461be3a6c794da44a4be1203c..45f52b20392a87f0ad6bfe49fe15e59ac6b0918d 100644 (file)
@@ -869,7 +869,7 @@ remove_contract_attributes (tree fndecl)
   tree list = NULL_TREE;
   for (tree p = DECL_ATTRIBUTES (fndecl); p; p = TREE_CHAIN (p))
     if (!cxx_contract_attribute_p (p))
-      list = tree_cons (TREE_PURPOSE (p), TREE_VALUE (p), NULL_TREE);
+      list = tree_cons (TREE_PURPOSE (p), TREE_VALUE (p), list);
   DECL_ATTRIBUTES (fndecl) = nreverse (list);
 }
 
index 2d8e4fdd4b55aac9904fd31b783b71d8a09e429d..08de273a90082916bc74f2f44cec865e4bac77fd 100644 (file)
@@ -11561,7 +11561,7 @@ tsubst_contract (tree decl, tree t, tree args, tsubst_flags_t complain,
   tree r = copy_node (t);
 
   /* Rebuild the result variable.  */
-  if (POSTCONDITION_P (t) && POSTCONDITION_IDENTIFIER (t))
+  if (type && POSTCONDITION_P (t) && POSTCONDITION_IDENTIFIER (t))
     {
       tree oldvar = POSTCONDITION_IDENTIFIER (t);