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]

Possible parser problem in v1.1.1



Greetings!

I have discovered what may be a bug in the egcs parser. I'm using egcs
v1.1.1 on a Tru64 Unix (formerly Digital Unix) system v4.0D. I see that
egcs has recently been updated to 1.1.2. However, I see no mention of my
possible bug on the 1.1.2 fixes page or on the known bugs page.

The program that manifests this problem is not very long. Here it is:

#include <iostream>
#include <iterator>
#include <vector>

void print(const std::vector<int> &vec);

int main()
{
  // Declares an object named vec, not a function named vec.
  std::vector<int>
    vec(std::istream_iterator<int>(std::cin), std::istream_iterator<int>());

  print(vec);
  return 0;
}

It is my intention here to create an object named vec of type vector<int>.
I'm using the template constructor to initialize the object and passing in
two input iterators. However, egcs thinks that vec is a function. This is
evident from the error message it produces at the call to print() where it
tries to convert a pointer to function into a reference to a vector (and
can't).

It is understandable that egcs would be confused by this declaration. The
two parameters to the constructor look very much like function parameter
declarations.

	istream_iterator<int> (std::cin)

This looks like a declaration of a parameter of type istream_iterator<int>
with a dummy name of std::cin and extra parenthesis around the declarator.

	istream_iterator<int>()

This looks like the name of the type "function taking no parameters and
returning istream_iterator<int>" with no dummy name provided.

The only clue to the real interpretation of the declaration is the
existence of the "std::" qualifier on cin. I don't believe such a
qualifier could be present on a dummy name in a parameter declaration.
Other than that, however, the constructor parameters do indeed look like
function parameter declarations. As I said, it is easy for me to see how
egcs got confused! In fact, I'm not totally convinced that this is really
a bug at all.

Just FYI... I presented this same program to Metrowerks CodeWarrior Pro4
and IBM's Visual Age C++ v4.0. CodeWarrior did parse the declaration as
the definition of an object (although it had other, unrelated problems
with the program). Visual Age C++ called the declaration an error and
flaged the std::cin saying that a namespace qualifier was not allowed
there. It obviously had committed itself to the idea that vec was a
function, but objected to the use of std:: on what it thought was a dummy
name.

I respectfully submit this information for your consideration. Make of it
what you will.

*****************************************************************************
Peter
pchapin@twilight.vtc.vsc.edu                   http://www.sover.net/~pchapin/




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