From nobody Fri Feb 21 18:39:46 2025 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YzzSl1qhgz5p6kr for ; Fri, 21 Feb 2025 18:39:51 +0000 (UTC) (envelope-from paulf2718@gmail.com) Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YzzSk19KGz434G for ; Fri, 21 Feb 2025 18:39:50 +0000 (UTC) (envelope-from paulf2718@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=jURiRkjW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of paulf2718@gmail.com designates 2a00:1450:4864:20::336 as permitted sender) smtp.mailfrom=paulf2718@gmail.com Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4398c8c8b2cso24973125e9.2 for ; Fri, 21 Feb 2025 10:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740163188; x=1740767988; darn=freebsd.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=NjFC7EIi1xTdZTpRfNaj/1e7ncYNoefYgSshbdHpbUE=; b=jURiRkjWMszC3KNrYurgyKh6KNVJ1DtQzoqTm1Fiuntwj+hCfIm+dIB//wM61ENoK7 3TbGvh5DXYyY1CwUsdB8RCnj2dPAbzePLpTXNenojyPOG5KopeX1BIZ7HeDZYz3BCWiQ EVZzUG9a8WVcJFIgUounC7EUeWUmJagKWX4PLIvIdotznaX9HuWGki6yxLJw6VE9S2ck sQzB2p6kIBopQaOg726q+THv1GsDMG2IKd4hkPdUCK8TyDWWC2616GOgErI8f2kWmbOV xRTVGK4j3H/LbpUwoSrdF4NVc3Y5d6mnWvx9C8C1WG7KZD7pfDpEFQjtorMVYuF0j2cp d5Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740163188; x=1740767988; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NjFC7EIi1xTdZTpRfNaj/1e7ncYNoefYgSshbdHpbUE=; b=FR0q6g0Lr8VppyroqxWktF/jS358lXo6ypxqTg3aDn3xdqHmuyfp1E7D4m0ugpQbEb K5aluta2PG79W/luTDXnW2ZmYvqWYltHq7puIBFMfICkunlkAP2jAdxUhpa29+1wUaoy Cv3FMtd/7MOE3xhrwsovH9le79/W812vRLazcyTQDLh93FPb0pg5psfTc3kyT2+0gu4H bp6LZEFWN7/P/MNxoxaiNlS5aAD6VkWt3el1bGgXngFqfRZxhxAC36y1rQ5RELy4gBwR UVhVzXvTF7I3p28Gf2S+J8B1YiknIUx3euQ8IMD8aPgXMGrWumffdH6FeGbVjSojbWNA E83Q== X-Gm-Message-State: AOJu0Yzs5Rw5uUP0qiE9PcJj0EUX5ZYiDMjoJwHzvDC0xeexz69ji3kR UerUh3kCxIZRYmuv1dpZCsQ6bhOWazIQqy9RJr4cYFW2CuCXB3CK9rSMH7eGi1c= X-Gm-Gg: ASbGnctLV27Yq1iWV8WiP2zae04rBUlNDs/rx4IpJtEpGwnJRYVoDJWZIQRreUQXFUM Pj5e/Yw0FT8S0wx/bnMvPS4i0DhJDYyeBeIIq/oMJLpMKRt568zaaPAZy2j8JYwrWHfJJRkL1LO D+GuruUKUa6rzrcoN28fhqIKMWNnNdgrsoIEtbufDTl2DOomakQtQMr2YOclEQwmsQnC1ri/j1S c0IoL5/VJ9cAa/jdQtzYoyOyPeXv7sbcYZ3jOf5gSykLlsmSqMp5oIFFBYpX+IMRUgcZ7k70uM3 Tforlpw8U0oAlVOXZPtL5khxAhNrmJQ9xovbGI44OyepciNGMu/+a9gwjaUxjbIXrwiMMn0N+54 = X-Google-Smtp-Source: AGHT+IGBkfrXVek1HpoS7JOi+QJb5t7uAVTy17Z9UrMjhrOTxpB37ef5NxRlVVp44sbSSxcRD6Okbw== X-Received: by 2002:a05:6000:1fa1:b0:38f:4cdc:5d21 with SMTP id ffacd0b85a97d-38f6e97a9dcmr4355305f8f.24.1740163187680; Fri, 21 Feb 2025 10:39:47 -0800 (PST) Received: from ?IPV6:2a01:cb15:8545:7700:62cf:84ff:fe81:caec? ([2a01:cb15:8545:7700:62cf:84ff:fe81:caec]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce37fsm25691335e9.8.2025.02.21.10.39.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Feb 2025 10:39:47 -0800 (PST) Message-ID: Date: Fri, 21 Feb 2025 19:39:46 +0100 List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@FreeBSD.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Empty structures have sizeof(1) in C++ now ? To: freebsd-current@freebsd.org References: <202502200940.51K9eswS003142@critter.freebsd.dk> <9A5B431C-2405-412A-90FF-DA016E80DF68@FreeBSD.org> Content-Language: en-US From: Paul Floyd In-Reply-To: <9A5B431C-2405-412A-90FF-DA016E80DF68@FreeBSD.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-3.00 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_FROM(0.00)[gmail.com]; FROM_HAS_DN(0.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-current@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-current@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::336:from] X-Rspamd-Queue-Id: 4YzzSk19KGz434G X-Spamd-Bar: -- On 2/20/25 12:03, David Chisnall wrote: > No, that’s always been the case in C++. It comes from the rule that two allocations must have unique addresses. If a structure could have size zero, an array of these structures would have size zero and the two elements in the array would have the same address. Similarly, two struct fields could have the same address, which breaks other bits of the language (pointers to members would compare equal when they should not). > > C++20 introduced the no_unique_address attribute. This allows you to embed a struct in another and, if the child struct has no fields, then its address is not required to be unique and you are explicitly saying that you won’t do any of the things where this would be a problem. > > This lets you do things like: > > ```c++ > template > struct SomeStructThatMayContainAnother > { > // Normal fields go here > > [[no_unique_address]] > std::conditional_t, struct {}, Embedded> embeddedStruct; > > // More fields maybe here > }; > ``` > > In this case, `embeddedStruct` will not add any space to the parent struct if the template parameter is `void`. There's also "EBO" (empty base optimization). https://en.cppreference.com/w/cpp/language/ebo Empty base classes aren't subject to the requirement that objexts should have an unique address. A+ Paul