This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] warning about empty extern "C" structures
Daniel Jacobowitz <drow@false.org> writes:
| On Wed, May 17, 2006 at 06:40:13PM +0200, Gabriel Dos Reis wrote:
| > OK, please explain it to me again.
| >
| > From my perspective
| >
| > extern "C" { struct S { }; }
| >
| > is not turning the C++ compiler to define a C program. So, the issue
| > here is whether it would cause a portability problem with C programs
| > -- this is a very rare case of C/c++ compatibility. It also appears
| > that the definition of S is permitted in GNU C with completely a
| > different meaning. Consequnently, the warning -- if we must have a
| > warning -- should not be confined to the C++ front-end...
|
| I can't get from your premises to your conclusion.
|
| - It is a valid C++ construct, so obviously we shouldn't warn about it
| in C++.
|
| - It is a valid C construct in the GNU dialects, so we shouldn't warn
| about it in C.
|
| - Using it in extern "C" in the GNU dialects is obviously broken, since
| it will be given the C++ layout, but the C version it is trying to
| interface will be given the C layout, and they will not match.
|
| I think that the only sensible options are warning or using the C
| layout within extern "C".
Notice so that extern "C" never change the ABI for structs, so it
cannot possibly be thought of "use the ABI at the intersection of C
and C++ for this struct".
|
| > The arguments for this patch hold verbatim.
|
| [for warning in C]
|
| Absolutely they don't. It has as clearly defined of a meaning in
| gcc -std=gnu89 as it does in g++; they happen to be different.
Notice that the issue is not that the construct does not have clear
meaning separately in each individual ghetto.