This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/20682] lost parser



------- Comment #11 from reichelt at gcc dot gnu dot org  2007-04-09 18:16 -------
This is really a non-bug.

The following code snippet illustrates this:

============================
#define VAR1(i,j) i##j
#define VAR2(i,j) VAR1(i,j)
#define VAR(i) VAR2(i,__LINE__)
#line 385
int VAR(i) = 0;
============================

The code snippet compiles fine on my i686-pc-linux-gnu machine.
If I add an empty line before the last line, I get the following error:

bug.cc:386: error: expected unqualified-id before numeric constant

A look at the preprocessed versions reveals the mystery.
First the "good" example:

============================
# 1 "bug.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "bug.cc"
# 385 "bug.cc"
int i385 = 0;
============================

The preprocessor magic constructs a variable consisting of the letter "i"
and the line number. That's also the case with the "bad" example.
But, "i386" is the name of another (compiler defined) macro which is
then substituted by its value "1":

============================
# 1 "bug.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "bug.cc"
# 385 "bug.cc"

int 1 = 0;
============================

I don't know how boost generates the variable names in your example,
but it looks like it uses a similar mechanism to turn line numbers
into variable names. The significant difference between yor "good" and
"bad" example is the following line which works fine with line number 388,
but not with 386:

- typedef typeof(to(0, models.size())) i_t388; i_t388& i388 = to(0,
models.size()); for(typename i_t388::iterator i = i388.begin(); i !=
i388.end(); ++i) {
+ typedef typeof(to(0, models.size())) i_t386; i_t386& 1 = to(0,
models.size()); for(typename i_t386::iterator i = 1 .begin(); i != 1 .end();
++i) {

So closing as funny/interesting, but still invalid.


-- 

reichelt at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]