[Bug c++/14693] New: Parse error using operator<<

loose at astron dot nl gcc-bugzilla@gcc.gnu.org
Tue Mar 23 13:58:00 GMT 2004


The following code demonstrates a parse error. I've run this code through 
several version of the g++ compiler (2.95.3, 3.1, 3.2.1, 3.2.3 and 3.3.2) and 
all exhibit the same behaviour. To check the validity of the code I also ran it 
through the Intel C++ compiler (v8.0) and it compiled fine.

$ cat g++-parser-bug.cc
#include <iostream>

using namespace std;

class Expr
{
public:
  Expr() {}
  friend Expr operator>(const Expr& lhs, const Expr& rhs) { return Expr(); }
  friend ostream& operator<<(ostream& os, const Expr& e) { return os; }
};

int main()
{
  cout << (Expr() > Expr()) << endl;
}

$ g++ -v -save-temps g++-parser-bug.cc
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-
checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cpp0 -lang-c++ -D__GNUG__=3 -
D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -
D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -
D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -
D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -
D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -
D__tune_i386__ g++-parser-bug.cc g++-parser-bug.ii
GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/3.2.2
 /usr/include/c++/3.2.2/i386-redhat-linux
 /usr/include/c++/3.2.2/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cc1plus -fpreprocessed g++-parser-
bug.ii -quiet -dumpbase g++-parser-bug.cc -version -o g++-parser-bug.s
GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (i386-redhat-linux)
        compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).
g++-parser-bug.cc: In function `int main()':
g++-parser-bug.cc:15: parse error before `>' token

-- 
           Summary: Parse error using operator<<
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: loose at astron dot nl
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list