220 37378 <3371255.CqAHtthudB@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: `offsetof` in a macro-less, modular world
Date: Sat, 17 Mar 2018 10:34:02 -0700
Lines: 40
Approved: news@gmane.org
Message-ID: <3371255.CqAHtthudB@tjmaciei-mobl1>
References: <c5f5ccc4-3267-442d-8cb2-de1ae103a38e@isocpp.org> <3998341.rfsqbO5A2U@tjmaciei-mobl1> <8fdfc016-2eb8-4888-9531-66310c80b457@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1521307926 15926 195.159.176.226 (17 Mar 2018 17:32:06 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 17 Mar 2018 17:32:06 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBDNDWXKQKGQEXYI4DVQ@isocpp.org Sat Mar 17 18:32:02 2018
Return-path: <std-proposals+bncBCB4TK757YBRBDNDWXKQKGQEXYI4DVQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f199.google.com ([209.85.220.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBDNDWXKQKGQEXYI4DVQ@isocpp.org>)
	id 1exFgV-00040a-PM
	for gclcip-std-proposals@m.gmane.org; Sat, 17 Mar 2018 18:31:59 +0100
Original-Received: by mail-qk0-f199.google.com with SMTP id d128sf8755354qkb.6
        for <gclcip-std-proposals@m.gmane.org>; Sat, 17 Mar 2018 10:34:07 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1521308046; cv=pass;
        d=google.com; s=arc-20160816;
        b=ij75PZuGrorKBoJh3ljfe9BFWH2pp0QqQEWtFK5G8RlGykmNWXwGhBdnZchTExj4Dk
         lTvJgnTTnwuA1iJQQocO3sCnaFqHuckczZVn3cLI/jm/1vLwwRXWsqR9GTQD2Ggp34Hi
         EKX2vB8FLdhXq2WTp1eumQkPTvyDwoSxo0E3tVGQXC5KIFTMaDXgsQfY7JtS7YIGD1UU
         CDmZHslihVZHc3hmHjHLPQXaIFdItuoQBnnYIcSVrzqIHP6jrFriVI0uf7zE4s9oP727
         1hHiGVh2Dhb5ne2cdI0x2/hf037FBeigIp3W2M8qaS3P/QUhX/Is6Hb1aPix547fpFRm
         lQyA==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:references
         :in-reply-to:message-id:date:subject:to:from
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=rHykm689cupYRAvKwYhdzmvATJrsVFppojZ/cSGka0s=;
        b=E/pBjTDLZwH9SBWBskD+ZOnTqsW3WGfUxsxrpKsZCF06BWfJPPzezhGS40En8MrQM2
         dAKygVNLELgMgwClIOUHaaDFEfSeGdEtRqMklbbbHh78k7yRRlHdR8zAy9rdXgDW+n4+
         FfhOI02vNipQu5y2+TVJiA/zMDbVm/5ieUYlVBtcbxHEQdVFCjNGPnug77YMHaUZFaAa
         wSKICYKSx3LQMqsTY/3UzAmgSKdReu/ih3tD+Ztqd07SVFxfKtSidWwVEFYhGOm+jNXV
         WLFwZkfPpPrzuajZu6zCZJtB60EYxAEH9yjkVzTyh9HT7LqjsnGkSQ1YV1v6MD/92Anw
         soXg==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=rHykm689cupYRAvKwYhdzmvATJrsVFppojZ/cSGka0s=;
        b=hVot3mEchJN53Ikpo+v9nYB8Sx3IG0114aCXJzscIOYpNF6LKZVQML+AM/n82Bsqdm
         1LcZ+aPV5RX5sumj7Zp93Dh1U34e63yxNmOgYVGOPOV+Ic2Dj9FEBEUk7Vx2ON15iQv2
         RhFFxHmRn03G9CEoFLCM29amuA55LyBBrox55OMBdzo4p8iX3yyIOdjIr+FY8YjNdEag
         Wdjh66ipDVHtE4KEbcTLHab29DoTL/IHJ2M6/MOk6rt797I9WeGm8CVG0BbLXXO3k+bF
         o8FFYaYSKX0MtXev3dSJr2ul20Eynsi7XMhAaE3Xxla3H4Z6dQaFcddq0JLu9PJ52xhd
         Z+Lg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=rHykm689cupYRAvKwYhdzmvATJrsVFppojZ/cSGka0s=;
        b=CGsgTDz+qLmR+7st82zBubkpc1nqKp9Mz2yz9R1Ox5ilUy1m1WQ+n6vwU1vaBEJAKX
         d1BcYpJap0oaTDIGxUNhQofdskla9ZQknLFzHdFIFvjIHW87Tgjb9sZo1+Ti8/oYLO0m
         ohIdm9u2/zl7sPqveJBhypsVXsrXmVEkabw/fqPJWl0d1wROx29pmffLP/B6GNqLBnZ9
         Y32laL7RR/w8gnrrhRDil5twWIwQQviJ79JtrNysbY2oCM9mzCjg/q2qZ+sTn4Ngw+QR
         /57PwLsBGaPjGW67GifedOXxWFYa3zhVW5YLKnjdrI2AXoiO0/Kz1v+w0B7D7agd0e+3
         1KFw==
X-Gm-Message-State: AElRT7EJ/+fLPddJtcZe3vsh44X/nHRfSlvK4zMEMrAEEUrQ7KzlzXkG
	AMA4B6W94BmhQS4aP3XnC3A5Bg==
X-Google-Smtp-Source: AG47ELvYxPLT8mk5LouLTxCMQZjeH8KHsp/fHJvTakdJV/DXsi/KdLAY3H6Q8fFRYk3NNU4OClMlWg==
X-Received: by 10.55.98.194 with SMTP id w185mr4028676qkb.34.1521308046469;
        Sat, 17 Mar 2018 10:34:06 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.55.182.194 with SMTP id g185ls4765617qkf.0.gmail; Sat, 17 Mar
 2018 10:34:05 -0700 (PDT)
X-Received: by 10.55.182.68 with SMTP id g65mr9443328qkf.41.1521308045156;
        Sat, 17 Mar 2018 10:34:05 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1521308045; cv=none;
        d=google.com; s=arc-20160816;
        b=yMkxnTRSoCJ0uXr5WJfSabCtVl6LmykKBRl7iVBJvG9aC4QjeU4pcJl21EmBAGjlAb
         Z4f9yhm16FlcU8vT5Jy/pSvdFTZ7VsWmLY/99pxwHSpVF79eL2eVsIt8QOGPP56aE1oV
         xjT1UULUd9CEGOmDQaIoVMjdG4f+y8DdxKLiGlffOXR/JLG+FPfF39WbTQ1X2BfLIBmI
         R8bkjNTMXVKHjkQiWgFJZVJa5TfztTNYWsS/AQaiTkhMvOXnyt+5f/nzfIgKMf/DmFPi
         VP1U6TkND7OK03vtsGsXI2n2ZqeSHOFVLfmsKfVPrcdTaMIIIvjoaYq5os0XXslw4pW5
         RGog==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from:arc-authentication-results;
        bh=Ejq+efNBCVEUR0xnTHf8iYje3UU3c+5AiFw/39Nw3RI=;
        b=Nh2XIlrMLGJKW9OTqfeVPKljkaQ2wwI+xqaoYYC0F4L4Ax9cTSsqQkV9uItFd1sTzr
         uIWEw0cp/dSRlaNqdQZoS6mIA9kJ0qQ2OjzQQ1hKO0ohv7FOkT5nXXFn79LTaV9bWqbm
         bklFJnWqkuj0f1Wy5L6JMDl0cdU3FDvOaV3ILoNrJhjKXb5aLVk0Y1O9fSPTPQWu56xb
         amz14VmLxobyQrtMKj4sZib5eRuQrrNVHFGNSfY/eL9OiF0pUVRG5jADcmr9QAnEb1+A
         14azsQw3f+Dcwiq90c/tjQSb1v/PIiGfGbUQHE6DMMqwPxHj2EUKoW7YwnjK6NfQv46o
         RZ+Q==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from smtp.macieira.info (arvernien.macieira.info. [209.222.10.136])
        by mx.google.com with ESMTPS id c8si616227qth.15.2018.03.17.10.34.04
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 17 Mar 2018 10:34:04 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) client-ip=209.222.10.136;
Original-Received: from tjmaciei-mobl1.localnet (unknown [IPv6:2601:1c0:4501:5f9f:4183:2825:a294:7ca8])
	by smtp.macieira.info (Postfix) with ESMTPSA id C1876A7DC
	for <std-proposals@isocpp.org>; Sat, 17 Mar 2018 10:34:03 -0700 (PDT)
In-Reply-To: <8fdfc016-2eb8-4888-9531-66310c80b457@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) smtp.mailfrom=thiago@macieira.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:37378
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37378>

On Saturday, 17 March 2018 03:11:11 PDT Jakob Riedle wrote:
> as a first contribution to this survey :-), I recently used it to
> determine, whether two attributes (used in two different memory layout
> modes of a class) shaddow each other.
> Here is the link to the spot (Line 667):
> https://github.com/DuffsDevice/tinyutf8/blob/master/include/tinyutf8.h

I think I understand what your optimisation is trying to do here: support the 
case where struct NON_SSO has tail padding, in which case the last byte in 
struct SSO aliases no members in NON_SSO. Is that it?

If so, the code is dead in all modern platforms, since sizeof(size_t) == 
sizeof(void *) and ditto for alignof. So NON_SSO will never have tail padding 
and it will be very hard for you to test this anywhere. Is this an 
optimisation you really want to keep in your code?

Though I don't see any other way to test for padding at a specific position 
aside from offsetof. That seems to be a legitimate use, though fragile and 
dangerous.

I also think that your code in that condition is UB. You can't use t_sso and 
t_non_sso at the same time -- only one member of a union can be active at a 
time. Since this function is supposed to disable SSO, you must leave the 
t_non_sso member of the union active at the end of your function, but the last 
one it would have used is t_sso.

Your last_byte<T> type may be suffering from the same problem.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center



-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3371255.CqAHtthudB%40tjmaciei-mobl1.

.
