From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115580 invoked by alias); 29 Mar 2017 15:46:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 115124 invoked by uid 89); 29 Mar 2017 15:46:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=era, Getting, lengths, stand X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Mar 2017 15:46:10 +0000 Received: by simark.ca (Postfix, from userid 33) id 3C20B1E80F; Wed, 29 Mar 2017 11:46:10 -0400 (EDT) To: Pedro Alves Subject: Re: [PATCH 4/5] Make sect_offset and cu_offset strong typedefs instead of structs X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 29 Mar 2017 15:46:00 -0000 From: Simon Marchi Cc: gdb-patches@sourceware.org In-Reply-To: <1490754298-9455-5-git-send-email-palves@redhat.com> References: <1490754298-9455-1-git-send-email-palves@redhat.com> <1490754298-9455-5-git-send-email-palves@redhat.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.4 X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00507.txt.bz2 On 2017-03-28 22:24, Pedro Alves wrote: > A while ago, back when GDB was a C program, the sect_offset and > cu_offset types were made structs in order to prevent incorrect mixing > of those offsets. Now that we require C++11, we can make them > integers again, while keeping the safety, by exploiting "enum class". > We can add a bit more safety, even, by defining operators that the > types _should_ support, helping making the suspicious uses stand out > more. > > Getting at the underlying type is done with the new to_underlying > function added by the previous patch, which also helps better spot > where do we need to step out of the safety net. Mostly, that's around > parsing the DWARF, and when we print the offset for complaint/debug > purposes. But there are other occasional uses. > > Since we have to define the sect_offset/cu_offset types in a header > anyway, I went ahead and generalized/library-fied the idea of "offset" > types, making it trivial to add more such types if we find a use. See > common/offset-type.h and the DEFINE_OFFSET_TYPE macro. > > I needed a couple generaly-useful preprocessor bits (e.g., yet another > CONCAT implementation), so I started a new common/preprocessor.h file. > > I included units tests covering the "offset" types API. These are > mostly compile-time tests, using SFINAE to check that expressions that > shouldn't compile (e.g., comparing unrelated offset types) really are > invalid and would fail to compile. This same idea appeared in my > pending enum-flags revamp from a few months ago (though this version > is a bit further modernized compared to what I had posted), and I plan > on reusing the "check valid expression" bits added here in that > series, so I went ahead and defined the CHECK_VALID_EXPR macro in its > own header -- common/valid-expr.h. I think that's nicer regardless. > > I was borderline between calling the new types "offset" types, or > "index" types, BTW. I stuck with "offset" simply because that's what > we're already calling them, mostly. A while ago (in the pre C++ era), I asked you if we could make some integer types that couldn't be assigned to each other, to represent 8-bit bytes and target bytes. That would help avoid mixing incompatible lengths or offsets for targets that have 16 or 32 bit bytes, forcing us to do the appropriate conversion. There was no way to do it in C. Do you think offset-type could be used for that now?