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


Groups > comp.lang.c > #150130

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

From Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups comp.lang.c
Subject Const-qualified function return type in C - is it a part of function type?
Date 2020-02-21 14:35 -0800
Organization A noiseless patient Spider
Message-ID <r2plun$4vl$1@dont-email.me> (permalink)

Show all headers | View raw


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.

-- 
Best regards,
Andrey Tarasevich

Back to comp.lang.c | Previous | Next — Next 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