From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id B2C433858D32 for ; Thu, 1 Dec 2022 23:54:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B2C433858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52e.google.com with SMTP id m19so4405810edj.8 for ; Thu, 01 Dec 2022 15:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7s21gYQaF12DPHGMYOdUwC1SL+zXlvWtRjznEbMpwqA=; b=hJnFdiTcvx+tc50D3mZEpcg2IC//L1GcJSW83/O6eSSmVdO9GyF2rHZOqmTv7WgIR/ o14r0wggJqGM42f6LLPr7oWnsVf+Md6gCW9AgVXsKte97vNAtstnYONgLzDSUnnwrA0h 6OxtFjAgiTKS1SV2RZR5O8nvAkZaBiwlbPgm84MSXCH67sN8eNQB07LrvY5wGBScpjSO W20cs21pC/ibBFDZZHJfr3+fkarzjUQVPpTSh8UV5p0o+ghad9ppL96xQEsAA8r8dPcr b3pVB1EI15GcQiXENCdW6Wz+P8gtwIdx4ZSnwnrc0PPNgpHlz9zIib8G1XTmdTcVEL9i Rg+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7s21gYQaF12DPHGMYOdUwC1SL+zXlvWtRjznEbMpwqA=; b=L+/SfEwZoxjXOBJCb0AkDxvvRflule3vFYi4CQMcp4ssvxGB6KvNCovG6ZwHG4H5e0 qtuPnicNodOnZOUFW9HtviLV/HHGj+jhPMlzoYpr7kmgalPFbcj1oJA3hgSXB5oxtyJL ecpEqMqbRosx2lKctKxkPjtKNotwI9AJNkKhnryD+LZAW1VaKZ9uh/FsCsNNdxmiohUZ SBvMLZmc9qF40tUJAbuBLdXHet7txrzISQcoMuRc9ueMSaWBJmtwFJefC9omVvlRemaR dOig0MqmLA/cU2yWmPBkyK5gj05lN9U3O1bH7qCWsDJgLfca1LzJivLgaLJhgGxEQg87 w+Bg== X-Gm-Message-State: ANoB5pkIMI0g7ehEVFAkeJWA0n2EBa1DbKMCX1eUmgR/zzYXXnZx6ANv HNN32GrtjwNhoN+G+uuwjqZCVFyFen5ReVjT4cE= X-Google-Smtp-Source: AA0mqf7J1QijauJdJJ4KDAA+51KRia7O96Vva2PcocZ3o2i5qmkEEtvTTYAh2xGfQHYkgXyYNiLRj68hhJFnL/qCCFk= X-Received: by 2002:aa7:c94a:0:b0:46b:74e1:872c with SMTP id h10-20020aa7c94a000000b0046b74e1872cmr14093664edt.301.1669938890442; Thu, 01 Dec 2022 15:54:50 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 1 Dec 2022 23:54:39 +0000 Message-ID: Subject: Re: which compiler is right (either to compile or to barf)... To: leon zadorin Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 1 Dec 2022 at 23:27, leon zadorin via Gcc-help wrote: > > On Thu, Dec 1, 2022 at 8:35 PM LIU Hao wrote: > > > > > I think this is a bug in Clang. Instantiation of `shared_ptr>` is not > > meant to instantiate > > `T`. Your code actually compiles fine if the definition of `J` was not > > provided. > > > > -- > > Best regards, > > LIU Hao > > > > Thanks :) It is rather interesting, there is a discussion at > https://github.com/llvm/llvm-project/issues/59292 > which may be pointing to implementation differences between stdlibc++ and > libc++ etc. > > There is thinknig that it just may be UB in the originally-posted code (if > so then clang is rather helpful there, but only when used with libstdc++ > apparently.. as I haven't personally verified the delta between building > against different libs :) :) ) > > The current thought prorcess is that std component must be allowed by the > standard to be instantiated with incomplete type T. And vector is allowed > so indeed (but I think it must be complete by the time its members, e.g. > via member-function invocation, are referenced)... so then it may come down > to std::optional and its implementation -- whether its ctor is referencing > any vector's members (dtor etc.) ... > > I suppose the official way would be to find whether ::std::optional may be > instantiated with incomplete type T It may not be. (say even if only when using default, > no value present, ctor overload)... and if it not mentioned of being able > to do so then it would be a bug in the original code (at which point having > some toolchain being able to detect it is rather super nice :) :) > > I dont know to be honest if standard's doco for such ctor , e.g. > constexpr optional() noexcept; constexpr optional(nullopt_t) noexcept; > Postconditions: *this does not contain a value. > > Remarks: No contained value is initialized. > > For every object type T these constructors are constexpr > constructors > > would be sufficient to infer the ability to instantiate with incomplete > type... probably not (I'm not enough of an expert to see through this with > my cloudy head atm :) Those constructors are irrelevant. It's undefined to instantiate *any* std::lib template with an incomplete type unless *explicitly* permitted. It is explicitly permitted for vector and shared_ptr. It is not permitted for optional.