public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/25880]  New: suggestion: a special warning for discarding the ``const'' qualifier
@ 2006-01-20 15:59 roland dot illig at gmx dot de
  2006-01-20 16:00 ` [Bug c/25880] " roland dot illig at gmx dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: roland dot illig at gmx dot de @ 2006-01-20 15:59 UTC (permalink / raw)
  To: gcc-bugs

The current gcc warning for discarded qualifiers cannot be easily understood by
beginners:

$ cat const.c
int main(void)
{
        const char *pcc;
        char *pc;

        pcc = "hello, world";
        pc = pcc;
        return 0;
}

$ gcc -Wall -W const.c 
const.c: In function `main':
const.c:7: warning: assignment discards qualifiers from pointer target type

This warning doesn't give any hint to a programmer not familiar with the ISO
standard's wording. Therefore I suggest to make a special case warning if the
only qualifier that's discarded is ``const''. It would then show up like this:

$ ~/pkg/gcc3/bin/gcc -Wall -W const.c 
const.c: In function `main':
const.c:7: warning: assignment discards ``const'' qualifier from pointer target
type


-- 
           Summary: suggestion: a special warning for discarding the
                    ``const'' qualifier
           Product: gcc
           Version: 3.3.5
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: roland dot illig at gmx dot de
 GCC build triplet: *-*-*
  GCC host triplet: *-*-*
GCC target triplet: *-*-*


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


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

* [Bug c/25880] suggestion: a special warning for discarding the ``const'' qualifier
  2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
@ 2006-01-20 16:00 ` roland dot illig at gmx dot de
  2006-01-20 16:04 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: roland dot illig at gmx dot de @ 2006-01-20 16:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from roland dot illig at gmx dot de  2006-01-20 15:59 -------
Created an attachment (id=10690)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10690&action=view)
Special warning for ``const''.


-- 


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


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

* [Bug c/25880] suggestion: a special warning for discarding the ``const'' qualifier
  2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
  2006-01-20 16:00 ` [Bug c/25880] " roland dot illig at gmx dot de
@ 2006-01-20 16:04 ` pinskia at gcc dot gnu dot org
  2010-06-04 15:16 ` [Bug c/25880] improve message of warning for discarding qualifiers manu at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-20 16:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-01-20 16:04 -------
Patches should go to gcc-patches@gcc.gnu.org.  

The correct quoting style is "%<const%>"  as %< and %> gets translated to the
corect quote for the person.

You might just say all the Quals which are discarded, there are only 3,
restrict, const and volatile.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2006-01-20 16:04:23
               date|                            |


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


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

* [Bug c/25880] improve message of warning for discarding qualifiers
  2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
  2006-01-20 16:00 ` [Bug c/25880] " roland dot illig at gmx dot de
  2006-01-20 16:04 ` pinskia at gcc dot gnu dot org
@ 2010-06-04 15:16 ` manu at gcc dot gnu dot org
  2010-06-04 15:22 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-06-04 15:16 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1872 bytes --]



------- Comment #3 from manu at gcc dot gnu dot org  2010-06-04 15:16 -------
Subject: Bug 25880

Author: manu
Date: Fri Jun  4 15:15:38 2010
New Revision: 160274

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160274
Log:
2010-06-04  Manuel López-Ibáñez  <manu@gcc.gnu.org>

        PR c/25880
        * c-objc-common.c (c_tree_printer): Handle %V, %v and %#v.
        * c-format.c (gcc_diag_flag_specs): Add hash.
        (gcc_cxxdiag_flag_specs): Use gcc_diag_flag_specs directly.
        (gcc_tdiag_char_table,gcc_cdiag_char_table): Handle %V and %v.
        * c-pretty-print.c (pp_c_cv_qualifier): Rename as
        pp_c_cv_qualifiers. Handle qualifiers spelling here.
        (pp_c_type_qualifier_list): Call the function above.
        * c-pretty-print.h (pp_c_cv_qualifiers): Declare.
        * c-typeck.c (handle_warn_cast_qual): Print qualifiers.
        (WARN_FOR_QUALIFIERS): New macro.
        (convert_for_assignment): Use it.
testsuite/
        * gcc.dg/assign-warn-2.c: Update.
        * gcc.dg/cpp/line3.c: Update.
        * gcc.dg/c99-array-lval-8.c: Update.
        * gcc.dg/cast-qual-2.c: Update.
        * gcc.dg/c99-arraydecl-3.c:  Update.
        * gcc.dg/assign-warn-1.c:  Update.
        * gcc.dg/format/gcc_diag-1.c:  Update.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-format.c
    trunk/gcc/c-objc-common.c
    trunk/gcc/c-pretty-print.c
    trunk/gcc/c-pretty-print.h
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/assign-warn-1.c
    trunk/gcc/testsuite/gcc.dg/assign-warn-2.c
    trunk/gcc/testsuite/gcc.dg/c99-array-lval-8.c
    trunk/gcc/testsuite/gcc.dg/c99-arraydecl-3.c
    trunk/gcc/testsuite/gcc.dg/cast-qual-2.c
    trunk/gcc/testsuite/gcc.dg/cpp/line3.c
    trunk/gcc/testsuite/gcc.dg/format/gcc_diag-1.c


-- 


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


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

* [Bug c/25880] improve message of warning for discarding qualifiers
  2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
                   ` (2 preceding siblings ...)
  2010-06-04 15:16 ` [Bug c/25880] improve message of warning for discarding qualifiers manu at gcc dot gnu dot org
@ 2010-06-04 15:22 ` manu at gcc dot gnu dot org
  2010-09-08 23:06 ` rmansfield at qnx dot com
  2010-09-08 23:34 ` manu at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-06-04 15:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2010-06-04 15:21 -------
The infrastructure to enable this has been added in GCC 4.6 and some
diagnostics are already making use of it, in particular the one reported here.
So I consider this FIXED. 

If anyone finds particular diagnostics that should explicitly print qualifiers,
they just need to use %qV, %qv or %q#v to do so. In that case, reopen this PR
or open a new one. Patches are also welcome.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug c/25880] improve message of warning for discarding qualifiers
  2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
                   ` (3 preceding siblings ...)
  2010-06-04 15:22 ` manu at gcc dot gnu dot org
@ 2010-09-08 23:06 ` rmansfield at qnx dot com
  2010-09-08 23:34 ` manu at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rmansfield at qnx dot com @ 2010-09-08 23:06 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 372 bytes --]



------- Comment #5 from rmansfield at qnx dot com  2010-09-08 23:05 -------
The changes done in pp_c_cv_qualifiers print "‘__attribute__((const))’"  or
'"__attribute__((noreturn))"' for function pointer even if they are defined
with 'const' or 'volatile' in the users code and this may be confusing for
some.


-- 


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


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

* [Bug c/25880] improve message of warning for discarding qualifiers
  2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
                   ` (4 preceding siblings ...)
  2010-09-08 23:06 ` rmansfield at qnx dot com
@ 2010-09-08 23:34 ` manu at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-09-08 23:34 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]



------- Comment #6 from manu at gcc dot gnu dot org  2010-09-08 23:33 -------
(In reply to comment #5)
> The changes done in pp_c_cv_qualifiers print "�__attribute__((const))�"  or
> '"__attribute__((noreturn))"' for function pointer even if they are defined
> with 'const' or 'volatile' in the users code and this may be confusing for
> some.

This is on purpose. There is no way to internally differentiate between these
two cases[*], so one has to decide to print one or the other. We decided the
current approach for function pointers was clearer, because (1) one should
really use the attributes and not volatile/const (2) one can lookup the
attributes and find out what they mean and that they are equivalent to
volatile/const. I hope this answers your question. 

[*] GCC is very far from retaining such detailed source-level information and
no one is working on improving this for the foreseeable future.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rmansfield at qnx dot com


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


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

end of thread, other threads:[~2010-09-08 23:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-20 15:59 [Bug c/25880] New: suggestion: a special warning for discarding the ``const'' qualifier roland dot illig at gmx dot de
2006-01-20 16:00 ` [Bug c/25880] " roland dot illig at gmx dot de
2006-01-20 16:04 ` pinskia at gcc dot gnu dot org
2010-06-04 15:16 ` [Bug c/25880] improve message of warning for discarding qualifiers manu at gcc dot gnu dot org
2010-06-04 15:22 ` manu at gcc dot gnu dot org
2010-09-08 23:06 ` rmansfield at qnx dot com
2010-09-08 23:34 ` manu at gcc dot gnu dot org

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).