From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 14EBB3858D34 for ; Sun, 12 Sep 2021 20:04:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14EBB3858D34 Received: by mail-wr1-x432.google.com with SMTP id b6so11278317wrh.10 for ; Sun, 12 Sep 2021 13:04:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=29XkF/qfFzOyUELmCA/EjLXnUwlKrNDMcV7oTfJhzIE=; b=cE1LuSbTW0yzjOFkWV0yu6IYvNYZWXT9hMjXAUov7DQlvbDGJLGR6XeGcWMiA6jlmQ iMAMo54wrsoCzqsbHcRJiY89YfvfCvU+bkHDS6boKMoyD4A64TkDooIJs7WXXOjuvF3b oo6ZOdcKiKlekPtw6qZy19eDAsGoh+5yU/7iKxni0+hdvwQpJ+Feq0x/PBxAJ8mDK6IO JlnpESosp0dqSoFolxVUGv24WKsA9/T5FjRdxyVEH6lf7zqzxzW6qObt1Ls8mRG9Yalq ym7ZBEfh4nHpTKkjOZv7xX3Tmw++bHQ08R4mjWZ2cyFD1Z6OwpHvDErR+J5eIXxfqh1s nIMQ== X-Gm-Message-State: AOAM530P8w9/L9Z4IzwBAQfP8NJeoU3hKEyCWIuFDaTv1WkMQFIqH85L +ejJobq2jIqrQQy3tz9iapaU40Zwdi1TiBI6h+E= X-Google-Smtp-Source: ABdhPJw+svRsb301SPhVOrNhBhnr9IJQbCQR2ZDELrN63T1fZGed7cfhROGLJ5wFPQ/8XJNw4S8daaR+d8Y+wweqIOg= X-Received: by 2002:a05:6000:1569:: with SMTP id 9mr8841775wrz.343.1631477088202; Sun, 12 Sep 2021 13:04:48 -0700 (PDT) MIME-Version: 1.0 References: <63CE1E9B-77D5-4E17-95FA-554B45C4028D@globus.software> In-Reply-To: From: Jonathan Wakely Date: Sun, 12 Sep 2021 21:04:36 +0100 Message-ID: Subject: Re: Forward declaration and std::future To: Evgen Bodunov Cc: "libstdc++" X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Sep 2021 20:04:53 -0000 On Sun, 12 Sep 2021, 19:30 Evgen Bodunov, wrote: > Hello Jonathan, > > Please, could you refer exact part and version of the standard? > Please reply to the mailing list, not just to me. Every version of the standard has the same requirement, see http://eel.is/c++draft/requirements#res.on.functions-2.5 std::promise requires its result type to be destructible. We are allowed to assert that by using is_destructible because we can assume the type is complete, because [res.on.functions] says it must be. In a correct program, the assertion will not fail. > On 12.09.2021, at 20:19, Jonathan Wakely wrote: > > > > On Sun, 12 Sep 2021, 10:36 Evgen Bodunov, wrote: > >> Hello everyone, >> >> During development of valhalla routing project I stumbled upon >> compilation error on gcc + libstdc++ 11 and newer when std::future >> constructed from forward declared class. Live example is there: >> https://godbolt.org/z/rEx3Eonsz It builds on gcc prior to v11. and on >> any clang with libc++. >> >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits: In >> instantiation of 'struct std::is_destructible': >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future:1065:21: >> required from 'class std::promise' >> :8:29: required from here >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:849:52: >> error: static assertion failed: template argument must be a complete class >> or an unbounded array >> 849 | >> static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), >> | >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:849:52: >> note: 'std::__is_complete_or_unbounded >> >((std::__type_identity{}, std::__type_identity()))' >> evaluates to false >> In file included from :1: >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future: In >> instantiation of 'class std::promise': >> :8:29: required from here >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future:1065:21: >> error: static assertion failed: result type must be destructible >> 1065 | static_assert(is_destructible<_Res>{}, >> | ^~~~~~~~~~~~~~~~~~~~~~~ >> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future:1065:21: >> note: 'std::is_destructible{}' evaluates to false >> Compiler returned: 1 >> >> Is that static assert is really required? May be then it should correctly >> process forward declared types? >> > > The standard says your code has undefined behaviour. The assertion is > pointing out your mistake. > > > >