Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #150155

Re: Const-qualified function return type in C - is it a part of function type?

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Const-qualified function return type in C - is it a part of function type?
Date 2020-02-22 09:53 -0800
Organization A noiseless patient Spider
Message-ID <861rqmcxuj.fsf@linuxsc.com> (permalink)
References <r2plun$4vl$1@dont-email.me>

Show all headers | View raw


Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> Here's the code
>
>   const int foo() { return 42; }
>
>   int main()
>   {
>     int (*pFunc)() = foo;
>   }
>
> (In C++ mode both GCC and Clang reject this code, which is expected.)
>
> When this code is compiled as C, GCC remains completely quiet, even in
> presence of `-pedantic`. Clang always issues a warning about the types
> being incompatible.  In `-pedantic-errors` mode Clang flags this as an
> error.
>
> So, what is it really?
>
> On the one hand, `const` in this case is applied to something that is
> definitely not an lvalue, which makes it "meaningless" per 6.7.3/5
> ("The properties associated with qualified types are meaningful only
> for expressions that are lvalues.")
>
> On the other hand, the concept of *compatible type* does not in any
> way rely on expression-specific context and on the concept of lvalue,
> which seems to suggest that Clang is right:  the types are not
> compatible here.

I agree with your statements downthread.  What clang does is
right, and what gcc does is wrong.  What the Standard says is
confusingly worded, but I don't see any other way to make
sense of it reasonably than to say const qualifiers on some
consituent elements of a function such (such as the return type
or parameter types) is /not/ what is being talked about in the
now-infamous sentence

    If the specification of a function type includes any type
    qualifiers, the behavior is undefined.

which indeed is meant to refer only to qualifiers on the function
type as a whole, not to qualifiers on any constitutent elements.

Sorry for the absurdly overly long sentence there;  I don't have
time to make it shorter.

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Const-qualified function return type in C - is it a part of function type? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-02-21 14:35 -0800
  Const-qualified function return type in C - is it a part of function type? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-21 15:24 -0800
    Re: Const-qualified function return type in C - is it a part of function type? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-02-21 16:19 -0800
      Re: Const-qualified function return type in C - is it a part of function type? Richard Damon <Richard@Damon-Family.org> - 2020-02-21 20:50 -0500
        Re: Const-qualified function return type in C - is it a part of function type? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-02-21 19:56 -0800
          Re: Const-qualified function return type in C - is it a part of function type? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-22 14:22 +0000
            Re: Const-qualified function return type in C - is it a part of function type? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-22 10:06 -0800
              Re: Const-qualified function return type in C - is it a part of function type? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-22 21:20 +0000
                Re: Const-qualified function return type in C - is it a part of function type? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-24 20:58 -0800
            Re: Const-qualified function return type in C - is it a part of function type? luser droog <luser.droog@gmail.com> - 2020-02-22 19:24 -0800
              Re: Const-qualified function return type in C - is it a part of function type? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-23 03:52 +0000
                Re: Const-qualified function return type in C - is it a part of function type? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-24 21:06 -0800
      Re: Const-qualified function return type in C - is it a part of function type? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-21 21:21 -0800
  Re: Const-qualified function return type in C - is it a part of function type? Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-22 07:51 +0100
    Re: Const-qualified function return type in C - is it a part of function type? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-02-22 05:00 -0800
      Re: Const-qualified function return type in C - is it a part of function type? Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-22 16:23 +0100
      Re: Const-qualified function return type in C - is it a part of function type? Guillaume <message@bottle.org> - 2020-02-22 20:37 +0100
        Re: Const-qualified function return type in C - is it a part of function type? Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-22 20:50 +0100
          Re: Const-qualified function return type in C - is it a part of function type? David Brown <david.brown@hesbynett.no> - 2020-02-23 07:29 +0100
            Re: Const-qualified function return type in C - is it a part of function type? Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-23 08:57 +0100
  Re: Const-qualified function return type in C - is it a part of function type? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-22 09:53 -0800

csiph-web