From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42668 invoked by alias); 20 Feb 2017 23:18:08 -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 42647 invoked by uid 89); 20 Feb 2017 23:18:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=201611, baking X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Feb 2017 23:18:06 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84D647FB63; Mon, 20 Feb 2017 23:18:06 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1KNI5We010597; Mon, 20 Feb 2017 18:18:05 -0500 Subject: Re: [PATCH] Default initialize enum flags to 0 To: Simon Marchi , gdb-patches@sourceware.org References: <20170220214548.18024-1-simon.marchi@ericsson.com> From: Pedro Alves Message-ID: Date: Mon, 20 Feb 2017 23:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170220214548.18024-1-simon.marchi@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00561.txt.bz2 On 02/20/2017 09:45 PM, Simon Marchi wrote: > ... so that we don't need to do it manually, and potentially forget. > For example, this allows to do: > > my_flags flags; > > ... > > flags |= some_flag; > > gdb/ChangeLog: > > * common/enum-flags.h (enum_flags::enum_flags): Initialize > m_enum_value to 0 in default constructor. Not sure I really like this. 3 reasons off hand. None are very strong, but let me put them out nonetheless: #1 - I have some desire of creating a "gdb/gnu template library" dir and moving these utilities there, in order to share them with more projects (e.g., gcc, and who knows, gold and who knows other parts of binutils that might want to convert to C++ in the future), and it'd be nice to keep the type behaving the same in C and C++ modes (that's why I had left the !__cplusplus branch in the file). [1]. #2 - The other reason is that it's nice IMO to leave enums and enum flags easily interchangeable -- i.e., make them behave as close as possible. Having one be default initialized, and the other value initialized means that when changing variables from one type to the other one needs to consider that aspect. #3 - Default initializing to zero can hide bugs that would otherwise be caught with -Winitialized. [1] - Trevor expressed something similar before too [2]: https://sourceware.org/ml/gdb-patches/2016-11/msg00114.html [2] - Yes, I need to find some time to post a v2 of that series. :-P (It's baking slowing on my github.) Thanks, Pedro Alves