]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: for contracts, cdtors never return this
authorAlexandre Oliva <oliva@adacore.com>
Wed, 29 Nov 2023 07:00:28 +0000 (04:00 -0300)
committerTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Fri, 9 Feb 2024 08:45:56 +0000 (09:45 +0100)
When targetm.cxx.cdtor_return_this() holds, cdtors have a
non-VOID_TYPE_P result, but IMHO this ABI implementation detail
shouldn't leak to the abstract language conceptual framework, in which
cdtors don't have return values.  For contracts, specifically those
that establish postconditions on results, such a leakage is present,
and the present patch puts an end to it: with it, cdtors get an error
for result postconditions regardless of the ABI.  This fixes
g++.dg/contracts/contracts-ctor-dtor2.C on arm-eabi.

for  gcc/cp/ChangeLog

* contracts.cc (check_postcondition_result): Cope with
cdtor_return_this.

(cherry picked from commit 71804526d3a71a8c0f189a89ce3aa615784bfd8b)

gcc/cp/contracts.cc

index 9d1cb558f4f72ebe78c3420667e7d33e664be595..18482e5c4c85fda2009026e09429768325854948 100644 (file)
@@ -636,7 +636,11 @@ make_postcondition_variable (cp_expr id)
 bool
 check_postcondition_result (tree decl, tree type, location_t loc)
 {
-  if (VOID_TYPE_P (type))
+  /* Do not be confused by targetm.cxx.cdtor_return_this ();
+     conceptually, cdtors have no return value.  */
+  if (VOID_TYPE_P (type)
+      || DECL_CONSTRUCTOR_P (decl)
+      || DECL_DESTRUCTOR_P (decl))
     {
       error_at (loc,
                DECL_CONSTRUCTOR_P (decl)