This is the mail archive of the
mailing list for the GCC project.
RE: Compiler warnings while compiling gcc with clang
- From: Aditya K <hiraditya at msn dot com>
- To: "pinskia at gmail dot com" <pinskia at gmail dot com>, Renato Golin <renato dot golin at linaro dot org>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 5 May 2015 11:39:30 +0000
- Subject: RE: Compiler warnings while compiling gcc with clang
- Authentication-results: sourceware.org; auth=none
- References: <BLU179-W15F1B75976EAA6915DFE1BB6D10 at phx dot gbl> <CA+=Sn1k+1NUE_o2mkWRad_-wgQuQCiyHPmNYc00zeH+N61qZXQ at mail dot gmail dot com> <CAMSE1kciuStXmVRor4Mc=qb78xZYarwdHAAz2xme7L00bajWuw at mail dot gmail dot com>,<55EE0A4A-97FF-4A75-867F-B91B9EAD00D1 at gmail dot com>
> CC: firstname.lastname@example.org; email@example.com
> From: firstname.lastname@example.org
> Subject: Re: Compiler warnings while compiling gcc with clang
> Date: Tue, 5 May 2015 01:11:38 -0700
> To: email@example.com
>> On May 5, 2015, at 1:00 AM, Renato Golin <firstname.lastname@example.org> wrote:
>>> On 5 May 2015 at 05:58, Andrew Pinski <email@example.com> wrote:
>>> These two are bogus and really clang in GCC's mind. The main reason
>>> is the standard says struct and class are the same thing.
>> Apart from the fact that classes are private by default and structs
>> are not. They may be similar for layout purposes, and it may be ok to
>> interchange them on local re-declarations when the compiler doesn't
>> need the type completely defined, but they're not the same thing.
> Read the standard again. They are the same. The standard is very clear they are the same.
>> The compiler might be smart and use the protection model that the
>> original declaration used (private/public), but what that warning is
>> saying is that you have refactored your code to include classes and
>> forgot to update all uses, which is a very valid warning. I can't see
>> why one would *want* to keep the "struct" keyword. If you're already
>> compiling in C++ mode, removing it from variable/argument declarations
>> should be valid, and re-declaring incomplete types should be made as
> No the warning is there to try to warn people about microsoft's c++ and nothing else.
At least for consistency/maintainability purposes it would be very useful to have either all structs or all classes.
There are however, other differences between class and struct (http://stackoverflow.com/a/999810/811335) i.e.,
1. In absence of an access-specifier for a base class, public is assumed when the derived class is declared struct and private is assumed when the class is declared class.
2. class can be used in place of a typename to declare a template parameter, while the struct cannot.