public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40960]  New: POSIX requires that option -D have a lower precedence than -U
@ 2009-08-04 11:52 vincent at vinc17 dot org
  2009-08-04 12:19 ` [Bug c/40960] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincent at vinc17 dot org @ 2009-08-04 11:52 UTC (permalink / raw)
  To: gcc-bugs

[This concerns the POSIX c99 utility, but gcc should probably behave in the
same way, as on some platforms, c99 is gcc.]

In http://www.opengroup.org/onlinepubs/9699919799/utilities/c99.html POSIX
specifies:

  -D  name[=value]
    Define name as if by a C-language #define directive. If no = value
    is given, a value of 1 shall be used. The -D option has lower
    precedence than the -U option. That is, if name is used in both a
    -U and a -D option, name shall be undefined regardless of the
    order of the options.

However, gcc doesn't take the precedence rule into account:

$ cat tst.c
int main(void)
{
#ifdef FOO
  return 1;
#else
  return 0;
#endif
}
$ c99 tst.c -UFOO -DFOO=1
$ ./a.out
zsh: exit 1     ./a.out

whereas FOO should be undefined and the return value should be 0, not 1.

I could reproduce this with various GCC versions, including:
gcc-snapshot (Debian 20090718-1) 4.5.0 20090718 (experimental) [trunk revision
149777]


-- 
           Summary: POSIX requires that option -D have a lower precedence
                    than -U
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vincent at vinc17 dot org


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


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

* [Bug c/40960] POSIX requires that option -D have a lower precedence than -U
  2009-08-04 11:52 [Bug c/40960] New: POSIX requires that option -D have a lower precedence than -U vincent at vinc17 dot org
@ 2009-08-04 12:19 ` rguenth at gcc dot gnu dot org
  2009-08-04 13:30 ` vincent at vinc17 dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-04 12:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-08-04 12:19 -------
Hm, I wonder how many makefiles we'd break with changing that.


-- 


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


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

* [Bug c/40960] POSIX requires that option -D have a lower precedence than -U
  2009-08-04 11:52 [Bug c/40960] New: POSIX requires that option -D have a lower precedence than -U vincent at vinc17 dot org
  2009-08-04 12:19 ` [Bug c/40960] " rguenth at gcc dot gnu dot org
@ 2009-08-04 13:30 ` vincent at vinc17 dot org
  2009-08-04 14:02 ` jakub at gcc dot gnu dot org
  2009-08-04 14:54 ` joseph at codesourcery dot com
  3 siblings, 0 replies; 5+ messages in thread
From: vincent at vinc17 dot org @ 2009-08-04 13:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from vincent at vinc17 dot org  2009-08-04 13:29 -------
There would the possibility to have a POSIX mode implied by c99, but I don't
think having different behaviors would be a good idea. IMHO, Makefiles should
be fixed to stick to POSIX.

Also, portable Makefiles, i.e. that work with other compilers, should not be
affected.

Note that Sun cc 5.0 is correct. And gcc 2.95.3 was also correct! (That's old,
but this is on an old Solaris machine where I still have an account.)


-- 


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


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

* [Bug c/40960] POSIX requires that option -D have a lower precedence than -U
  2009-08-04 11:52 [Bug c/40960] New: POSIX requires that option -D have a lower precedence than -U vincent at vinc17 dot org
  2009-08-04 12:19 ` [Bug c/40960] " rguenth at gcc dot gnu dot org
  2009-08-04 13:30 ` vincent at vinc17 dot org
@ 2009-08-04 14:02 ` jakub at gcc dot gnu dot org
  2009-08-04 14:54 ` joseph at codesourcery dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-08-04 14:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2009-08-04 14:01 -------
And the GCC behavior makes much more sense than the POSIX required for c99.


-- 


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


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

* [Bug c/40960] POSIX requires that option -D have a lower precedence than -U
  2009-08-04 11:52 [Bug c/40960] New: POSIX requires that option -D have a lower precedence than -U vincent at vinc17 dot org
                   ` (2 preceding siblings ...)
  2009-08-04 14:02 ` jakub at gcc dot gnu dot org
@ 2009-08-04 14:54 ` joseph at codesourcery dot com
  3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2009-08-04 14:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from joseph at codesourcery dot com  2009-08-04 14:54 -------
Subject: Re:  POSIX requires that option -D have a lower precedence
 than -U

On Tue, 4 Aug 2009, vincent at vinc17 dot org wrote:

> There would the possibility to have a POSIX mode implied by c99, but I don't
> think having different behaviors would be a good idea. IMHO, Makefiles should

I think that installing a variant driver program as "c99", that implements 
the different semantics, is exactly the right thing to do here; the 
present semantics are more useful for "gcc".  We should have a configure 
option to install "cc", "c89" and "c99" drivers; they should have 
appropriate defaults regarding e.g. standards mode, and should also adjust 
the precedence of these options and make any other adjustments required by 
POSIX that aren't appropriate for "gcc".


-- 


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


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

end of thread, other threads:[~2009-08-04 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-04 11:52 [Bug c/40960] New: POSIX requires that option -D have a lower precedence than -U vincent at vinc17 dot org
2009-08-04 12:19 ` [Bug c/40960] " rguenth at gcc dot gnu dot org
2009-08-04 13:30 ` vincent at vinc17 dot org
2009-08-04 14:02 ` jakub at gcc dot gnu dot org
2009-08-04 14:54 ` joseph at codesourcery 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).