public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Default warnings and useless extensions (e.g. arithmetic on void *)
@ 2008-06-09 13:46 Vincent Lefevre
  2008-06-09 14:02 ` Richard Guenther
  0 siblings, 1 reply; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-09 13:46 UTC (permalink / raw)
  To: gcc

Is there any reason why "gcc -Wall" doesn't emit warnings by default
on some useless extensions such as pointer arithmetic on (void *)?

IMHO, such an extension is useless because there's an easy workaround:
use casts to char *. And since g++ barfs on pointer arithmetic on
void *, such a warning would be very useful. BTW, gcc is also silent
when -Wc++-compat is used! With gcc/g++ 4.3.1:

vin% cat ptrarith.c
void *foo (void *p)
{
  return p + 1;
}
vin% gcc -Wall -Wc++-compat -c ptrarith.c
vin% g++ -c ptrarith.c
ptrarith.c: In function 'void* foo(void*)':
ptrarith.c:3: error: pointer of type 'void *' used in arithmetic
vin% 

So, basically shouldn't -Wpointer-arith (and possible other ones) be
added to the options enabled by -Wall?

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on void *)
  2008-06-09 13:46 Default warnings and useless extensions (e.g. arithmetic on void *) Vincent Lefevre
@ 2008-06-09 14:02 ` Richard Guenther
  2008-06-09 14:08   ` Manuel López-Ibáñez
  2008-06-10  7:07   ` Vincent Lefevre
  0 siblings, 2 replies; 16+ messages in thread
From: Richard Guenther @ 2008-06-09 14:02 UTC (permalink / raw)
  To: gcc

On Mon, Jun 9, 2008 at 3:46 PM, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> Is there any reason why "gcc -Wall" doesn't emit warnings by default
> on some useless extensions such as pointer arithmetic on (void *)?

Use -pedantic to warn about extensions.  It doesn't make sense to
warn for extensions if they are not deprecated.  After all they are extensions.

Richard.

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

* Re: Default warnings and useless extensions (e.g. arithmetic on void *)
  2008-06-09 14:02 ` Richard Guenther
@ 2008-06-09 14:08   ` Manuel López-Ibáñez
  2008-06-09 14:11     ` Richard Guenther
  2008-06-10  7:07   ` Vincent Lefevre
  1 sibling, 1 reply; 16+ messages in thread
From: Manuel López-Ibáñez @ 2008-06-09 14:08 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

2008/6/9 Richard Guenther <richard.guenther@gmail.com>:
> On Mon, Jun 9, 2008 at 3:46 PM, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
>> Is there any reason why "gcc -Wall" doesn't emit warnings by default
>> on some useless extensions such as pointer arithmetic on (void *)?
>
> Use -pedantic to warn about extensions.  It doesn't make sense to
> warn for extensions if they are not deprecated.  After all they are extensions.

Nonetheless, I think that the part about -Wc++-compat not warning
about pointer of type 'void *' used in arithmetic is a valid
criticism. Don't you agree?

Cheers,

Manuel.

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

* Re: Default warnings and useless extensions (e.g. arithmetic on void *)
  2008-06-09 14:08   ` Manuel López-Ibáñez
@ 2008-06-09 14:11     ` Richard Guenther
  0 siblings, 0 replies; 16+ messages in thread
From: Richard Guenther @ 2008-06-09 14:11 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: gcc

On Mon, Jun 9, 2008 at 4:07 PM, Manuel López-Ibáñez
<lopezibanez@gmail.com> wrote:
> 2008/6/9 Richard Guenther <richard.guenther@gmail.com>:
>> On Mon, Jun 9, 2008 at 3:46 PM, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
>>> Is there any reason why "gcc -Wall" doesn't emit warnings by default
>>> on some useless extensions such as pointer arithmetic on (void *)?
>>
>> Use -pedantic to warn about extensions.  It doesn't make sense to
>> warn for extensions if they are not deprecated.  After all they are extensions.
>
> Nonetheless, I think that the part about -Wc++-compat not warning
> about pointer of type 'void *' used in arithmetic is a valid
> criticism. Don't you agree?

Yes.  But -Wc++-compat is far from complete.

Richard.

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-09 14:02 ` Richard Guenther
  2008-06-09 14:08   ` Manuel López-Ibáñez
@ 2008-06-10  7:07   ` Vincent Lefevre
  2008-06-10  9:26     ` Richard Guenther
                       ` (2 more replies)
  1 sibling, 3 replies; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-10  7:07 UTC (permalink / raw)
  To: gcc

On 2008-06-09 16:02:05 +0200, Richard Guenther wrote:
> Use -pedantic to warn about extensions. It doesn't make sense to
> warn for extensions if they are not deprecated. After all they are
> extensions.

The problem with -pedantic is that it gives lots of spurious warnings.
We have code that uses useful (i.e. with no workarounds) extensions
and that is protected by #if, e.g.

#ifdef HAVE_LONG_LONG
            case LONG_LONG_ARG:
              *(long long *) p = (long long) nchar;
              break;
#endif

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on void *)
  2008-06-10  7:07   ` Vincent Lefevre
@ 2008-06-10  9:26     ` Richard Guenther
  2008-06-10 12:22       ` Vincent Lefevre
  2008-06-10 10:46     ` Tim Prince
  2008-06-10 11:43     ` Joseph S. Myers
  2 siblings, 1 reply; 16+ messages in thread
From: Richard Guenther @ 2008-06-10  9:26 UTC (permalink / raw)
  To: gcc

On Tue, Jun 10, 2008 at 9:07 AM, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> On 2008-06-09 16:02:05 +0200, Richard Guenther wrote:
>> Use -pedantic to warn about extensions. It doesn't make sense to
>> warn for extensions if they are not deprecated. After all they are
>> extensions.
>
> The problem with -pedantic is that it gives lots of spurious warnings.
> We have code that uses useful (i.e. with no workarounds) extensions
> and that is protected by #if, e.g.
>
> #ifdef HAVE_LONG_LONG
>            case LONG_LONG_ARG:
>              *(long long *) p = (long long) nchar;
>              break;
> #endif

In this specific case selecting C99 would fix it.  (-std=c99 -pedantic)

Richard.

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

* Re: Default warnings and useless extensions (e.g. arithmetic on   void *)
  2008-06-10  7:07   ` Vincent Lefevre
  2008-06-10  9:26     ` Richard Guenther
@ 2008-06-10 10:46     ` Tim Prince
  2008-06-10 10:53       ` Andrew Pinski
  2008-06-10 12:29       ` Vincent Lefevre
  2008-06-10 11:43     ` Joseph S. Myers
  2 siblings, 2 replies; 16+ messages in thread
From: Tim Prince @ 2008-06-10 10:46 UTC (permalink / raw)
  To: gcc

Vincent Lefevre wrote:
> On 2008-06-09 16:02:05 +0200, Richard Guenther wrote:
>   
>> Use -pedantic to warn about extensions. It doesn't make sense to
>> warn for extensions if they are not deprecated. After all they are
>> extensions.
>>     
>
> The problem with -pedantic is that it gives lots of spurious warnings.
> We have code that uses useful (i.e. with no workarounds) extensions
> and that is protected by #if, e.g.
>
> #ifdef HAVE_LONG_LONG
>             case LONG_LONG_ARG:
>               *(long long *) p = (long long) nchar;
>               break;
> #endif
>
>   
long long is an extension, if you don't specify -std=c99. You ask for 
warnings about extensions, you get them.  Why didn't you post this on 
gcc-help?

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

* Re: Default warnings and useless extensions (e.g. arithmetic on   void *)
  2008-06-10 10:46     ` Tim Prince
@ 2008-06-10 10:53       ` Andrew Pinski
  2008-06-10 12:29       ` Vincent Lefevre
  1 sibling, 0 replies; 16+ messages in thread
From: Andrew Pinski @ 2008-06-10 10:53 UTC (permalink / raw)
  To: tprince; +Cc: gcc



Sent from my iPhone

On Jun 10, 2008, at 11:45, Tim Prince <TimothyPrince@sbcglobal.net>  
wrote:

> Vincent Lefevre wrote:
>> On 2008-06-09 16:02:05 +0200, Richard Guenther wrote:
>>
>>> Use -pedantic to warn about extensions. It doesn't make sense to
>>> warn for extensions if they are not deprecated. After all they are
>>> extensions.
>>>
>>
>> The problem with -pedantic is that it gives lots of spurious  
>> warnings.
>> We have code that uses useful (i.e. with no workarounds) extensions
>> and that is protected by #if, e.g.
>>
>> #ifdef HAVE_LONG_LONG
>>            case LONG_LONG_ARG:
>>              *(long long *) p = (long long) nchar;
>>              break;
>> #endif
>>
>>
> long long is an extension, if you don't specify -std=c99. You ask  
> for warnings about extensions, you get them.  Why didn't you post  
> this on gcc-help?

Also -Wno-long-long will disable the warning for long long. :)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on   void *)
  2008-06-10  7:07   ` Vincent Lefevre
  2008-06-10  9:26     ` Richard Guenther
  2008-06-10 10:46     ` Tim Prince
@ 2008-06-10 11:43     ` Joseph S. Myers
  2008-06-10 12:50       ` Vincent Lefevre
  2 siblings, 1 reply; 16+ messages in thread
From: Joseph S. Myers @ 2008-06-10 11:43 UTC (permalink / raw)
  To: Vincent Lefevre; +Cc: gcc

On Tue, 10 Jun 2008, Vincent Lefevre wrote:

> On 2008-06-09 16:02:05 +0200, Richard Guenther wrote:
> > Use -pedantic to warn about extensions. It doesn't make sense to
> > warn for extensions if they are not deprecated. After all they are
> > extensions.
> 
> The problem with -pedantic is that it gives lots of spurious warnings.
> We have code that uses useful (i.e. with no workarounds) extensions
> and that is protected by #if, e.g.
> 
> #ifdef HAVE_LONG_LONG
>             case LONG_LONG_ARG:
>               *(long long *) p = (long long) nchar;
>               break;
> #endif

For this particular extension, you can use the more specific warning 
-Wpointer-arith.

There was a discussion of possible changes that would facilitate better 
warning control for -pedantic and pedwarns 
<http://gcc.gnu.org/ml/gcc-patches/2008-02/msg00970.html>.  You could then 
more simply add additional options for fine-grained control of particular 
-pedantic pedwarns.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-10  9:26     ` Richard Guenther
@ 2008-06-10 12:22       ` Vincent Lefevre
  0 siblings, 0 replies; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-10 12:22 UTC (permalink / raw)
  To: gcc

On 2008-06-10 11:26:32 +0200, Richard Guenther wrote:
> On Tue, Jun 10, 2008 at 9:07 AM, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> > On 2008-06-09 16:02:05 +0200, Richard Guenther wrote:
> >> Use -pedantic to warn about extensions. It doesn't make sense to
> >> warn for extensions if they are not deprecated. After all they are
> >> extensions.
> >
> > The problem with -pedantic is that it gives lots of spurious warnings.
> > We have code that uses useful (i.e. with no workarounds) extensions
> > and that is protected by #if, e.g.
> >
> > #ifdef HAVE_LONG_LONG
> >            case LONG_LONG_ARG:
> >              *(long long *) p = (long long) nchar;
> >              break;
> > #endif
> 
> In this specific case selecting C99 would fix it.  (-std=c99 -pedantic)

Of course, one can't use -std=c99, because not everyone has gcc 4.x.
So, the problem is still there. And even -std=gnu99 -pedantic doesn't
solve the problem since there are other spurious warnings (for code
enabled by the preprocessor if the compiler is gcc). Now I think that
this can be dealt with by making the configure.in even more complex. :(

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-10 10:46     ` Tim Prince
  2008-06-10 10:53       ` Andrew Pinski
@ 2008-06-10 12:29       ` Vincent Lefevre
  2008-06-10 12:41         ` Robert Dewar
  2008-06-10 12:46         ` Jakub Jelinek
  1 sibling, 2 replies; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-10 12:29 UTC (permalink / raw)
  To: gcc

On 2008-06-10 06:45:43 -0400, Tim Prince wrote:
> long long is an extension, if you don't specify -std=c99.

I know that. But I can't use -std=c99 because it doesn't work with
old gcc versions.

> You ask for warnings about extensions, you get them.

No, I'm not asking warnings about extensions. I'm asking warnings
about *useless* extensions, i.e. those for which a portable workaround
is possible, e.g. replace p + 1 by (char *) p + 1 when p is a void *.

> Why didn't you post this on gcc-help?

Because this is a feature request.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on   void *)
  2008-06-10 12:29       ` Vincent Lefevre
@ 2008-06-10 12:41         ` Robert Dewar
  2008-06-10 13:04           ` Vincent Lefevre
  2008-06-10 12:46         ` Jakub Jelinek
  1 sibling, 1 reply; 16+ messages in thread
From: Robert Dewar @ 2008-06-10 12:41 UTC (permalink / raw)
  To: gcc

Vincent Lefevre wrote:
> On 2008-06-10 06:45:43 -0400, Tim Prince wrote:
>> long long is an extension, if you don't specify -std=c99.
> 
> I know that. But I can't use -std=c99 because it doesn't work with
> old gcc versions.
> 
>> You ask for warnings about extensions, you get them.
> 
> No, I'm not asking warnings about extensions. I'm asking warnings
> about *useless* extensions, i.e. those for which a portable workaround
> is possible, e.g. replace p + 1 by (char *) p + 1 when p is a void *.

Clearly if everyone agreed that an extension was useless it would
not be there, so this argument makes no sense to me.
> 
>> Why didn't you post this on gcc-help?
> 
> Because this is a feature request.
> 

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-10 12:29       ` Vincent Lefevre
  2008-06-10 12:41         ` Robert Dewar
@ 2008-06-10 12:46         ` Jakub Jelinek
  2008-06-10 13:17           ` Vincent Lefevre
  1 sibling, 1 reply; 16+ messages in thread
From: Jakub Jelinek @ 2008-06-10 12:46 UTC (permalink / raw)
  To: gcc

On Tue, Jun 10, 2008 at 02:29:24PM +0200, Vincent Lefevre wrote:
> On 2008-06-10 06:45:43 -0400, Tim Prince wrote:
> > long long is an extension, if you don't specify -std=c99.
> 
> I know that. But I can't use -std=c99 because it doesn't work with
> old gcc versions.

It works with old, even very old gcc versions.  Only doesn't work with
prehistoric ones.  Already GCC 3.0 and even 2.96-RH supported -std=c99.

	Jakub

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-10 11:43     ` Joseph S. Myers
@ 2008-06-10 12:50       ` Vincent Lefevre
  0 siblings, 0 replies; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-10 12:50 UTC (permalink / raw)
  To: gcc

On 2008-06-10 11:43:11 +0000, Joseph S. Myers wrote:
> For this particular extension, you can use the more specific warning 
> -Wpointer-arith.

I've added that to the default options for gcc in MPFR's configure.in.
I've seen it works with gcc 2.95.2 (which is AFAIK the latest gcc for
a non-reflashed Zaurus), so I don't think there should be any problem.
But there may be other missing useful warnings.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-10 12:41         ` Robert Dewar
@ 2008-06-10 13:04           ` Vincent Lefevre
  0 siblings, 0 replies; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-10 13:04 UTC (permalink / raw)
  To: gcc

On 2008-06-10 08:40:40 -0400, Robert Dewar wrote:
> Clearly if everyone agreed that an extension was useless it would
> not be there, so this argument makes no sense to me.

Any example?

BTW, there should still be the possibility to use __extension__ to
avoid the warning.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

* Re: Default warnings and useless extensions (e.g. arithmetic on  void *)
  2008-06-10 12:46         ` Jakub Jelinek
@ 2008-06-10 13:17           ` Vincent Lefevre
  0 siblings, 0 replies; 16+ messages in thread
From: Vincent Lefevre @ 2008-06-10 13:17 UTC (permalink / raw)
  To: gcc

On 2008-06-10 15:00:32 +0200, Jakub Jelinek wrote:
> It works with old, even very old gcc versions.  Only doesn't work with
> prehistoric ones.  Already GCC 3.0 and even 2.96-RH supported -std=c99.

I remember having problems with gcc 3.x and -std=c99 because the
C library was too old.

Also, I think we should go back to at least gcc 2.95.2.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

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

end of thread, other threads:[~2008-06-10 13:17 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-09 13:46 Default warnings and useless extensions (e.g. arithmetic on void *) Vincent Lefevre
2008-06-09 14:02 ` Richard Guenther
2008-06-09 14:08   ` Manuel López-Ibáñez
2008-06-09 14:11     ` Richard Guenther
2008-06-10  7:07   ` Vincent Lefevre
2008-06-10  9:26     ` Richard Guenther
2008-06-10 12:22       ` Vincent Lefevre
2008-06-10 10:46     ` Tim Prince
2008-06-10 10:53       ` Andrew Pinski
2008-06-10 12:29       ` Vincent Lefevre
2008-06-10 12:41         ` Robert Dewar
2008-06-10 13:04           ` Vincent Lefevre
2008-06-10 12:46         ` Jakub Jelinek
2008-06-10 13:17           ` Vincent Lefevre
2008-06-10 11:43     ` Joseph S. Myers
2008-06-10 12:50       ` Vincent Lefevre

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