From: Jason Merrill Date: Wed, 30 Nov 2022 19:22:03 +0000 (-0500) Subject: c++: small contracts fixes X-Git-Tag: basepoints/gcc-14~2774 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4304e09a1617bcf1c87f5bc96017ae5017379d75;p=thirdparty%2Fgcc.git c++: small contracts fixes 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. --- diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index a90970167686..45f52b20392a 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -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); } diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 2d8e4fdd4b55..08de273a9008 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -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);