public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>, Martin Sebor <msebor@gmail.com>,
	Nathan Sidwell <nathan@acm.org>,
		Richard Biener <rguenther@suse.de>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 0/3] add support for POD struct convention (PR 61339)
Date: Fri, 12 Jul 2019 15:14:00 -0000	[thread overview]
Message-ID: <CADzB+2m0xQhEVYKADNzNLeccpG7=DODBLojVhoOP4qwVfexnrg@mail.gmail.com> (raw)
In-Reply-To: <20190712114213.GK4665@redhat.com>

On Fri, Jul 12, 2019 at 7:42 AM Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On 12/07/19 10:24 +0200, Jakub Jelinek wrote:
> >On Mon, Jul 08, 2019 at 03:56:51PM -0600, Martin Sebor wrote:
> >> A couple of GCC's Coding Conventions call to
> >>
> >>   1) Use the struct keyword for plain old data (POD) types.
> >>      https://www.gnu.org/software/gcc/codingrationale.html#struct
> >>
> >> and
> >>
> >>   2) Use the class keyword for non-POD types.
> >>      https://www.gnu.org/software/gcc/codingconventions.html#Class_Use
> >
> >This is a coding convention that has been added without any discussion
> >whatsoever on that, maybe it was some Google internal coding convention or
> >something, do we really want to enforce it rather than discuss
> >and decide what we actually want?
> >
> >With my limited C++ knowledge, the main distinction between struct and class
> >when both can appear interchangeably is that struct defaults to public:
>
> The default applies to class members and base classes, but that's the
> *only* distinction.
>
> >and class defaults to private:, and I think it is best to use those that
> >way, rather than having tons of class ... { public: ... } everywhere.
> >
> >There are many C++ class boolean properties, rather than just
> >POD vs. non-POD and we could pick any of them instead of this particular one
> >for the struct vs. class distinction if we wanted to enforce it, but why?

I agree.  The class-key used to define a class has very little signalling value.

> I'm also unconvinced that POD is a useful distinction. A class might
> be a POD today, but then we decide to add a default constructor to it
> (or if/when we move to C++11, add default member initializers to it).
> Does that mean we need to replace struct with class to follow this
> convention?
>
> Or we might decide to add a std::string member to it, which stops it
> being a POD. Should every reference to it be changed from struct to
> class?

Indeed.

> Personally I think "no user-defined constructors" might be a more
> useful distinction than POD. This is not a POD (because of the
> std::string member) but I don't see why it should be a class not a
> struct:
>
> struct A {
>   std::string name;
>   int id;
> };

In other words, "aggregate".

But I'm not sure even that is useful as a rule.  If someone wants to
add a constructor to their aggregate to allow parenthesized
initialization, but otherwise use the data members directly, having to
add "public:" at the top is useless boilerplate.

> >I'd just arrange that when being compiled with clang we compile with
> >-Wno-mismatched-tags to get rid of their misdesigned warning

Perhaps, but we might as well use the same tag.

Jason

  reply	other threads:[~2019-07-12 14:36 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-08 21:58 Martin Sebor
2019-07-08 21:59 ` [PATCH 1/3] add -Wstruct-not-pod, -Wclass-is-pod, -Wmismatched-tags " Martin Sebor
2019-07-22 16:39   ` Martin Sebor
2019-08-01 18:09     ` Jason Merrill
2019-08-01 23:35       ` Martin Sebor
2019-08-05 19:25         ` Jason Merrill
2019-08-05 21:56           ` Martin Sebor
2019-08-05 22:43             ` Jason Merrill
2019-12-03 21:49               ` [PATCH] add " Martin Sebor
2019-12-04 23:37                 ` Jason Merrill
2019-12-05 23:33                   ` Martin Sebor
2019-12-05 23:47                     ` Jakub Jelinek
2019-12-06 19:08                       ` Jason Merrill
2019-12-10  0:29                         ` Martin Sebor
2019-12-16 16:35                           ` Martin Sebor
2019-12-16 23:01                           ` Jason Merrill
2019-12-16 23:36                             ` Martin Sebor
2019-12-17 19:41                               ` Jason Merrill
2020-02-18  8:42                 ` Stephan Bergmann
2020-02-18 15:57                   ` Martin Sebor
2019-07-22 22:37   ` [PATCH 1/3] add -Wstruct-not-pod, -Wclass-is-pod, " Jeff Law
2019-07-23  0:00     ` Mike Stump
2019-07-23  1:34     ` Martin Sebor
2019-07-24 17:43       ` Jeff Law
2019-07-24 19:30   ` Jeff Law
2019-07-08 22:02 ` [PATCH 2/3] change class-key of PODs to struct and others to class " Martin Sebor
2019-07-08 22:20   ` Martin Sebor
2019-07-09 14:11     ` Richard Sandiford
2019-07-09 16:37       ` Martin Sebor
2019-07-08 22:04 ` [PATCH 3/3] " Martin Sebor
2019-07-09 15:19   ` Richard Sandiford
2019-07-09 18:53     ` Martin Sebor
2019-07-10  9:40       ` Richard Biener
2019-07-10 10:52         ` Richard Sandiford
2019-07-12  8:41 ` [PATCH 0/3] add support for POD struct convention " Jakub Jelinek
2019-07-12 11:44   ` Jonathan Wakely
2019-07-12 15:14     ` Jason Merrill [this message]
2019-07-12 15:26     ` Martin Sebor
2019-07-12 15:36       ` Jonathan Wakely
2019-07-12 16:29         ` Martin Sebor
2019-07-12 15:40       ` Jason Merrill
2019-07-12 16:49         ` Martin Sebor
2019-08-14 18:50   ` Pedro Alves
2019-08-19 19:15     ` Jason Merrill
2019-07-23 16:20 ` Arvind Sankar
2019-07-23 16:42   ` Martin Sebor
2019-07-23 16:54     ` Arvind Sankar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADzB+2m0xQhEVYKADNzNLeccpG7=DODBLojVhoOP4qwVfexnrg@mail.gmail.com' \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jwakely@redhat.com \
    --cc=msebor@gmail.com \
    --cc=nathan@acm.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).