Re: g++ 10: static declared in extern "C" inline function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Feb 2020 at 06:45, Sam Varshavchik <mrsam@xxxxxxxxxxxxxxx> wrote:
>
> Iñaki Ucar writes:
>
> > On Sun, 9 Feb 2020 at 14:20, Sam Varshavchik <mrsam@xxxxxxxxxxxxxxx> wrote:
> > >
> > > Iñaki Ucar writes:
> > >
> > > > Thoughts?
> > > >
> > > > [1] https://gist.github.com/kevinushey/cfa848be2d39ddd110f893d9b6c5ac9c
> > >
> > > I managed to find the part of the C++ standard that specified the semantics
> > > of extern "C" linkage, it is [dcl.link]. The term used is "language
> > linkage".
> > >
> > > There is no such thing as an inline function in C. That code compiles C++
> > > code with C language linkage.
> > >
> > > Reading the C++ standard,, all that the standard seems to specify is
> > > language linkage of declarations. Quoting:
> > >
> > > # Every implementation shall provide for linkage to functions written in
> > the C
> > > # programming language, "C", and linkage to C ++ functions, "C++".
> > > #
> > > # [ Example:
> > > # complex sqrt(complex);
> > > #  // C++ linkage by default
> > > # extern "C" {
> > > # double sqrt(double);
> > > #  // C linkage
> > > # }
> > > # — end example ]
> > >
> > > The standard does not seem to specify the definitions of functions inside
> > > a language linkage specification. Either that is unspecified and therefore
> > > is a compiler extension; or it is clear that the only thing that belongs
> > > inside extern "C" is C code, and there's no such thing as inline functions
> > > in C, so declaring C++ code with C linkage would also be considered a
> > > compiler extension.

I missed that bit in your previous email: of course there are inline
functions in C since C99.

> > > This code compiles in gcc 9, but not in gcc 10. That's life, for compiler
> > > extensions.
> >
> > So, summing up, nothing wrong with that code according to the
> > standard. Therefore, since this is a regression that breaks previous
> > behaviour, I'd say this is a bug in gcc, right?
>
> No, exactly the opposite. As I wrote:
>
> > > Reading the C++ standard,, all that the standard seems to specify is
> > > language linkage of declarations.
>
> The code that fails to compile is not a declaration. It defines an inline
> C++ function. I find nothing in C++ standard that specifies function
> definitions inside linkage specifications.
>
> This is a declaration:
>
> void foo();
>
> This is a definition:
>
> void bar()
> {
> }

What are you talking about? The same chapter you referenced,
[dcl.link], talks about definitions. Of course if you declare
something that will be available from C, you need to define it at some
point. Whether it's defined there or just declared and defined later
doesn't matter. The linkage only refers to the visibility of the
symbol, but it doesn't change the fact that every declaraction needs a
definition somewhere, and that must be (in this case) valid C++ code,
because it will be compiled with a C++ compiler.

Iñaki
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux