New: Bad diagnostic pasting tokens with ##
18 answers - 453 bytes -

The following invalid code snippet generates a bogus error message since
GCC 3.1:
#define foo - ## >>
foo;
bug.c:2:1: error: pasting "->" and ">>" does not give a valid preprocessing
token
bug.c:2: error: expected identifier or '(' before '->' token
The problem is that we tried to paste "-" and ">>" and not "->" and ">>".
GCC 3.0.x produced a correct diagnostic.
No.1 | | 131 bytes |
| 
--
reichelt at gcc dot gnu dot org changed:
What |Removed |Added
Target Milestone| |4.0.4
No.2 | | 128 bytes |
| 
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
Severity|normal |minor
No.3 | | 397 bytes |
| 
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
AssignedTo|unassigned at gcc dot gnu |jakub at gcc dot gnu dot org
|dot org |
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2006-
| |08/msg00548.html
Status|UNCNFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2006-08-16 16:19:10
date| |
No.4 | | 122 bytes |
| 
--
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
Priority|P3 |P2
No.5 | | 93 bytes |
| 
Comment #1 from mmitchel at gcc dot gnu dot org 2006-10-11 22:30
This patch is K, thanks.
No.6 | | 569 bytes |
| 
Comment #2 from jakub at gcc dot gnu dot org 2006-10-12 09:26
Subject: Bug 28709
Author: jakub
Date: Thu 12 09:25:59 2006
New Revision: 117664
URL:
Log:
PR preprocessor/28709
* macro.c (paste_tokens): Do error reporting here, use BUF with the
spelled LHS token as opposed to spelling it again.
(paste_all_tokens): Don't report errors here, just break on failure.
* gcc.dg/cpp/paste14.c: New test.
Added:
Modified:
trunk/gcc/testsuite/ChangeLog
trunk/libcpp/ChangeLog
trunk/libcpp/macro.c
No.7 | | 487 bytes |
| 
Comment #4 from tromey at gcc dot gnu dot org 2006-12-28 04:22
FWIW what happens here is that 'foo;' is turned into
'->>;' by cpp; then the second error is emitted by the
C parser. You can easily see this by comparing the -E output
against the output.
The problem here is that paste_tokens backs up over
the '>>' token, but it leaves the half-pasted '->' token
in *plhs. I have a fix that I'm testing.
No.8 | | 212 bytes |
| 
Comment #5 from patchapp at dberlin dot org 2007-01-01 21:57
Subject: Bug number PR preprocessor/28709
A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
No.9 | | 113 bytes |
| 
Comment #6 from gdr at gcc dot gnu dot org 2007-02-03 18:54
Won't fix in GCC-4.0.x. Adjusting milestone.
No.10 | | 135 bytes |
| 
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
Target Milestone|4.1.3 |4.1.2
No.11 | | 136 bytes |
| 
--
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
Target Milestone|4.1.2 |4.1.3
No.12 | | 458 bytes |
| 
Comment #7 from ahs3 at fc dot hp dot com 2007-03-07 00:49
Is this code snippet related to this bug, or a new one entirely?
#define LABEL(a, b) a##b##:
int main () {
LABEL(all,done)
return 0;
}
If I compile it:
$ gcc -o foo.o foo.c
foo.c:4:1: error: pasting "alldone" and ":" does not give a valid preprocessing
token
However, if I use -E first, and compile the result, the snippet compiles
properly,
No.13 | | 629 bytes |
| 
Comment #8 from pinskia at gcc dot gnu dot org 2007-03-07 00:58
(In reply to comment #7)
Is this code snippet related to this bug, or a new one entirely?
Actually the error message is fully correct in that case.
$ gcc -o foo.o foo.c
foo.c:4:1: error: pasting "alldone" and ":" does not give a valid preprocessing
token
However, if I use -E first, and compile the result, the snippet compiles
properly,
I don't, I get an error even with -E on the mainline, 3.3.5, and 4.0.2:
gcc t.c -E -o t.i
t.c:4:1: error: pasting "alldone" and ":" does not give a valid preprocessing
token
No.14 | | 921 bytes |
| 
Comment #9 from ahs3 at fc dot hp dot com 2007-03-07 18:43
Ah, my fault; I wasn't being clear. I still get the error message with -E,
that is true. However, the resulting code from cpp I thought was correct -- it
just produces what I thought was a normal C label, and if I ignore the error
message, I can compile the output from -E just fine. It seems to me that if
cpp no longer recognizes ##, then the message should say so ('deprecated cpp
token', or something); if cpp does recognize ##, then I don't think the error
message should be produced at all since the resulting tokens ('alldone:') are
valid C source.
If none of those are the case, what bit of info am I not understanding? And
I'm still not sure this is the same bug as the original report -- it seems
similar, but let me know if it's something different entirely.
Thanks.
No.15 | | 413 bytes |
| 
Comment #10 from pinskia at gcc dot gnu dot org 2007-03-07 21:39
(In reply to comment #9)
If none of those are the case, what bit of info am I not understanding?
Yes "alldone:" are really two seperate tokens in C :).
If you change the definition of LABEL to:
#define LABEL(a, b) a##b :
it works exactly the same as you want it to work.
And yes it is unrelated to this bug really.
No.16 | | 122 bytes |
| 
Comment #11 from tromey at gcc dot gnu dot org 2007-04-25 01:29
Bug 31182 has been marked as a duplicate of this bug.
No.17 | | 487 bytes |
| 
Comment #12 from tromey at gcc dot gnu dot org 2007-05-02 20:33
Subject: Bug 28709
Author: tromey
Date: Wed May 2 19:33:44 2007
New Revision: 124356
URL:
Log:
libcpp
PR preprocessor/28709:
* macro.c (paste_tokens): Remove PASTE_LEFT from the old lhs.
gcc/testsuite
PR preprocessor/28709:
* gcc.dg/cpp/pr28709.c: New file.
Added:
Modified:
trunk/gcc/testsuite/ChangeLog
trunk/libcpp/ChangeLog
trunk/libcpp/macro.c
No.18 | | 145 bytes |
| 
Comment #13 from tromey at gcc dot gnu dot org 2007-05-02 20:34
I checked in the follow-up patch to the trunk.
So this fully works on 4.3.