public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/20262] New: __LINE__ implementation flaky.
@ 2005-03-01 15:59 david dot pye at osm dot co dot uk
  2005-03-01 17:16 ` [Bug preprocessor/20262] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: david dot pye at osm dot co dot uk @ 2005-03-01 15:59 UTC (permalink / raw)
  To: gcc-bugs

The following code snippet triggers the assert.

Interestingly, the exact message that you get depends on the gcc version. 2.9x
gives you a "6+1 != 6" message, where 3.x gives you a "7+1 != 7".

On gcc3.3.5:
silly: sillytest.c:7: main: Assertion `((7) + 1 == (7))' failed.
Aborted

The code is as follows.

#include <assert.h>
#define macro(a, b) ((a) + 1 == (b))
int
main(void)
{
       assert(macro(__LINE__
                , __LINE__));
       return 0;
}

You're not alone - the only compiler I've found that does what I expect is the
SunWorkshop Pro compiler. Pretty much all the rest mess up somewhere along the line!

Cheers,

David

-- 
           Summary: __LINE__ implementation flaky.
           Product: gcc
           Version: 3.3.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: david dot pye at osm dot co dot uk
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug preprocessor/20262] __LINE__ implementation flaky.
  2005-03-01 15:59 [Bug preprocessor/20262] New: __LINE__ implementation flaky david dot pye at osm dot co dot uk
@ 2005-03-01 17:16 ` pinskia at gcc dot gnu dot org
  2005-03-01 23:13 ` neil at daikokuya dot co dot uk
  2005-03-01 23:36 ` neil at daikokuya dot co dot uk
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-01 17:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-01 17:16 -------
Outer Macros are expanded before inner ones and they get all placed on one line so this is invalid.

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


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


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

* [Bug preprocessor/20262] __LINE__ implementation flaky.
  2005-03-01 15:59 [Bug preprocessor/20262] New: __LINE__ implementation flaky david dot pye at osm dot co dot uk
  2005-03-01 17:16 ` [Bug preprocessor/20262] " pinskia at gcc dot gnu dot org
@ 2005-03-01 23:13 ` neil at daikokuya dot co dot uk
  2005-03-01 23:36 ` neil at daikokuya dot co dot uk
  2 siblings, 0 replies; 4+ messages in thread
From: neil at daikokuya dot co dot uk @ 2005-03-01 23:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From neil at daikokuya dot co dot uk  2005-03-01 23:13 -------
Subject: Re:  __LINE__ implementation flaky.

pinskia at gcc dot gnu dot org wrote:-

> 
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-01 17:16 -------
> Outer Macros are expanded before inner ones and they get all placed on one line so this is invalid.

Huh? This is a bug.

The reason it happens is nothing to do with inner or outer macros,
but the fact that arguments are collected before being expanded,
and an implementation detail where we don't take the line from the
token (otherwise __LINE__ would be misexpanded if the RHS of a
macro definition) but from the global line counter.

It may not be worth fixing; I suspect the reason other implementations
fail too is that it's hard to get it right, and the ability to easily
do so is heavily dependent on exactly how your preprocessor is
implemented.  (a bit like the #s vs %:s bug).

Neil.


-- 


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


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

* [Bug preprocessor/20262] __LINE__ implementation flaky.
  2005-03-01 15:59 [Bug preprocessor/20262] New: __LINE__ implementation flaky david dot pye at osm dot co dot uk
  2005-03-01 17:16 ` [Bug preprocessor/20262] " pinskia at gcc dot gnu dot org
  2005-03-01 23:13 ` neil at daikokuya dot co dot uk
@ 2005-03-01 23:36 ` neil at daikokuya dot co dot uk
  2 siblings, 0 replies; 4+ messages in thread
From: neil at daikokuya dot co dot uk @ 2005-03-01 23:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From neil at daikokuya dot co dot uk  2005-03-01 23:36 -------
Subject: Re:  __LINE__ implementation flaky.

neil at daikokuya dot co dot uk wrote:-

> 
> ------- Additional Comments From neil at daikokuya dot co dot uk  2005-03-01 23:13 -------
> Subject: Re:  __LINE__ implementation flaky.
> 
> pinskia at gcc dot gnu dot org wrote:-
> 
> > 
> > ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-01 17:16 -------
> > Outer Macros are expanded before inner ones and they get all placed on one line so this is invalid.
> 
> Huh? This is a bug.

Actually I take that back - I think you can say that the wording
of the standard is sufficiently vague that this is not a bug, and
may even be correct behaviour.  The standard says that (at the time
of expansion) it's the "presumed current source line of the file".
Since expansion happens after argument collection, it's not hard
to argue that the current source line of the file is constant for
both __LINE__ tokens.

Neil.


-- 


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


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

end of thread, other threads:[~2005-03-01 23:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-01 15:59 [Bug preprocessor/20262] New: __LINE__ implementation flaky david dot pye at osm dot co dot uk
2005-03-01 17:16 ` [Bug preprocessor/20262] " pinskia at gcc dot gnu dot org
2005-03-01 23:13 ` neil at daikokuya dot co dot uk
2005-03-01 23:36 ` neil at daikokuya dot co dot uk

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