public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/57133] New: false const qualifier warning typedef
@ 2013-05-01 10:35 grpintar at gmail dot com
  2013-05-01 11:38 ` [Bug c/57133] " mikpe at it dot uu.se
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: grpintar at gmail dot com @ 2013-05-01 10:35 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57133

             Bug #: 57133
           Summary: false const qualifier warning typedef
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: grpintar@gmail.com


typedef char *type;

void f(const type t)
{

}

int main(void)
{
    const char *str = "string";
    f(str);
    return 0;
}

warning: passing argument 1 of 'f' discards 'const' qualifier from pointer
target type [enabled by default]
  f(str);
  ^
note: expected 'type' but argument is of type 'const char *'
 void f(const type t)
      ^

It is similar with gcc 4.5.3.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/57133] false const qualifier warning typedef
  2013-05-01 10:35 [Bug c/57133] New: false const qualifier warning typedef grpintar at gmail dot com
@ 2013-05-01 11:38 ` mikpe at it dot uu.se
  2013-05-01 12:04 ` redi at gcc dot gnu.org
  2013-05-01 12:43 ` grpintar at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: mikpe at it dot uu.se @ 2013-05-01 11:38 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57133

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2013-05-01 11:37:56 UTC ---
(In reply to comment #0)
> typedef char *type;
> 
> void f(const type t)
> {

This doesn't do what you think it does.  t is now a const variable of type
char*, not a variable of type const char*.  Observe:

> cat pr57133.c
typedef char *type;
void f(const type t) { t = 0; }
void g(const type t) { *t = 0; }
> gcc -Wall -S pr57133.c
pr57133.c: In function 'f':
pr57133.c:2:1: error: assignment of read-only parameter 't'

The warning in your main() is correct.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/57133] false const qualifier warning typedef
  2013-05-01 10:35 [Bug c/57133] New: false const qualifier warning typedef grpintar at gmail dot com
  2013-05-01 11:38 ` [Bug c/57133] " mikpe at it dot uu.se
@ 2013-05-01 12:04 ` redi at gcc dot gnu.org
  2013-05-01 12:43 ` grpintar at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2013-05-01 12:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57133

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-05-01 12:04:36 UTC ---
.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/57133] false const qualifier warning typedef
  2013-05-01 10:35 [Bug c/57133] New: false const qualifier warning typedef grpintar at gmail dot com
  2013-05-01 11:38 ` [Bug c/57133] " mikpe at it dot uu.se
  2013-05-01 12:04 ` redi at gcc dot gnu.org
@ 2013-05-01 12:43 ` grpintar at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: grpintar at gmail dot com @ 2013-05-01 12:43 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57133

--- Comment #3 from grpintar at gmail dot com 2013-05-01 12:43:28 UTC ---
(In reply to comment #1)
> (In reply to comment #0)
> > typedef char *type;
> > 
> > void f(const type t)
> > {
> 
> This doesn't do what you think it does.  t is now a const variable of type
> char*, not a variable of type const char*.  Observe:
> 
> > cat pr57133.c
> typedef char *type;
> void f(const type t) { t = 0; }
> void g(const type t) { *t = 0; }
> > gcc -Wall -S pr57133.c
> pr57133.c: In function 'f':
> pr57133.c:2:1: error: assignment of read-only parameter 't'
> 
> The warning in your main() is correct.

I see. Sorry.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-05-01 12:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-01 10:35 [Bug c/57133] New: false const qualifier warning typedef grpintar at gmail dot com
2013-05-01 11:38 ` [Bug c/57133] " mikpe at it dot uu.se
2013-05-01 12:04 ` redi at gcc dot gnu.org
2013-05-01 12:43 ` grpintar at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).