First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 20262
Product:  
Component:  
Status: RESOLVED
Resolution: INVALID
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: David Pye <david.pye@osm.co.uk>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 20262 depends on: Show dependency tree
Show dependency graph
Bug 20262 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2005-03-01 15:58
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

------- Comment #1 From Andrew Pinski 2005-03-01 17:16 -------
Outer Macros are expanded before inner ones and they get all placed on one line
so this is invalid.

------- Comment #2 From Neil Booth 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.

------- Comment #3 From Neil Booth 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.

First Last Prev Next    No search results available      Search page      Enter new bug