From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id ADD13384F95D for ; Sat, 10 Dec 2022 18:35:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ADD13384F95D 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-ej1-x631.google.com with SMTP id fc4so18660172ejc.12 for ; Sat, 10 Dec 2022 10:35:25 -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=N1xBaJamB2hDx4eJfLe4c6/etysTFa4namtFisepLYA=; b=Ug4v8wVyO58nA5hFaDhpeD/etW7Duzutl3kOWqRqRsqJk7A42rS/+Lu0jRXtFboPFc Jbq7Uj8lCJic3tbtZx8GZ2mJ3QR7cEh3nDnxw9LJ0pypXZo1Kb+eqR0HlWLy3bV6lhvj uCkfD+DyXLtzRy8Rscr7EfR25GdVNtY2KoYqhG71Z40dbLOH77NH0RJkVX7O47B1mH5q GVfISsSY89kx0yonopsf0RRoppFICcSTFqzs1mtBaAjVbTI0N6oGjsN6dJrbfKm/xm1J pqbArmE5HeNCNW9r72j3W+KypBgzg/9H9xIO919qz1+c8jWDoajFBCNADcppUkWO7+Lw 0ShQ== 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=N1xBaJamB2hDx4eJfLe4c6/etysTFa4namtFisepLYA=; b=swcHqIBXQm55UYCMMXZxV9lH/92XJcYlGDtDXH1Ux46+gJwwwfhou8wJn5jbvMGfXL KcMH09DQEuW9ZCd98NWqz1jWQMTSm8I89nuipnK0KU30C4o2AhNkC479EV/lv1jZrgcc BDOC/qMOu9opS+2dYIrSMwHYOcsWhYTsVmRvYOB0HB/b3975RnxLGsdGsaE8Cqq/SKKU T+p8O3Z2zOnIA6KG7b6bCL+gml69xGePJx+eJVH2Ep7GT09yntydtB5KvoscOBn4Pi12 It10T1G6DyomIF0CybnCcz8ntjmgpFH1xsw3Ui9g4QrQN3CYgvMQUEwry7HXx6VfZ4WJ Vunw== X-Gm-Message-State: ANoB5pld7xP0EmS1GQeygjJOENhavMl44UreyuBgBXHOgpWWh3GSmrLd 1QoP0CIxTieXqWkZz9bMaIiw4Xkzz3nR0jOPRP4= X-Google-Smtp-Source: AA0mqf41YfkFSFmwBkQD8cj9jltSe1mTm0cI4/pXGPGMBaJiYG+4P38XRZ0SDPnLDmDfvLGfgflPLnfgsmagOBs4ilA= X-Received: by 2002:a17:907:cf84:b0:78d:4795:ff1f with SMTP id ux4-20020a170907cf8400b0078d4795ff1fmr35298159ejc.331.1670697324365; Sat, 10 Dec 2022 10:35:24 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Sat, 10 Dec 2022 18:35:13 +0000 Message-ID: Subject: Re: Bug with GCC's handling of lifetimes of implicit-lifetime types To: Gavin Ray Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.7 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 Sat, 10 Dec 2022 at 17:42, Gavin Ray via Gcc wrote: > > This came up when I was asking around about what the proper way was to: > > - Allocate aligned storage for a buffer pool/page cache > - Then create pointers to "Page" structs inside of the storage memory area > > I thought something like this might do: > > struct buffer_pool > { > alignas(PAGE_SIZE) std::byte storage[NUM_PAGES * PAGE_SIZE]; > page* pages = new (storage) page[NUM_PAGES]; > } > > Someone told me that this was a valid solution but not to do it, because it > wouldn't function properly on GCC > They gave this as a reproduction: > > https://godbolt.org/z/EhzM37Gzh > > I'm not experienced enough with C++ to grok the connection between this > repro and my code, Me neither. I don't think there is any connection, because I don't think the repro shows what they think it shows. > but I figured > I'd post it on the mailing list in case it was useful for others/might get > fixed in the future =) > > They said it had to do with "handling of lifetimes of implicit-lifetime > types" I don't think that code is a valid implementation of start_lifetime_as. Without a proper implementation of start_lifetime_as (which GCC doesn't provide yet), GCC does not allow you to read the bytes of a float as an int, and doesn't give you the bytes of 1.0f, it gives you 0. https://godbolt.org/z/dvncY9Pea works for GCC. But this has nothing to do your code above, as far as I can see.