This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Google SoC Project proposal: Wcoercion option


On 06/05/06, Mike Stump <mrs@apple.com> wrote:
On May 4, 2006, at 4:44 PM, lopezibanez@gmail.com wrote:
>>    struct C : A, B { /* ... */ };
>
> I am sorry to say that I don't understand the definition of struct C.

C is derived from A and B. Only valid of course in C++.


OK. This is multiple inheritance. I must admit I have never used this feature with structs. Also, my plan was to start with C and from simple types to more complex ones. Nevertheless, this may be an opportunity to refresh my C++ and also to learn about the internals of g++ and how to properly define Wcoercion in the context of classes and inheritance.

I created the following test program from your example:

#include <iostream>
using namespace std;

struct A { int i; };
struct B { double i; };
struct C : A,B { long double i; };

void fB(struct B* b);
void fB(struct B* b)
{
   cout << sizeof(b) << ", " << b << endl;
   return;
}
void fC(struct C* c);
void fC(struct C* c)
{
   cout << sizeof(c) << ", " << c << endl;
   return;
}

int main(void)
{
   struct C c;
   cout << sizeof(&c) << ", " << &c << endl;
   fB(&c);
   fC(&c);
   return 0;
}

The output is:
4, 0xbfe8c4f0
4, 0xbfe8c4f4
4, 0xbfe8c4f0

and thus, in the case of fB() there is a coercion that changes a value
that doesn't happen for fC(). However, you can never use b as (C *).
That would produce a compilation error.

Honestly, I see that there is a change of value, however, I don't see
what problems may arise from such change (apart from the situation
where you compare the values of the pointers). Until new arguments are
provided, my provisional decision would be to include this testcase as
one that should not generate a warning.

Gabriel, do you mind if I include your email address in the
description of the testcase for future reference?

Cheers,
Manu.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]