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]

g++ bug (?) with modern C++ constructs



Hello.

I think I've found a bug in g++. It may be reproduced both on sparc-solaris2.6
with gcc 2.95.2, and on Debian GNU/Linux system with gcc version 2.95.2
20000220.

The code that is in the attachment (that uses only standard things) causes a
parse error:
g++t.cpp: In function `void f()':
g++t.cpp:21: parse error before `>'

Absolutely the same code in non-template function g() compiles correctly.

You may find the code, the preprocessed code and g++ -v output in the
attachment.

I'll be happy to see this fixed ...

#include <typeinfo>
#include <cstddef>
using namespace std;

struct auto_typeid 
{
	virtual void __never_use_me() {}
	template<class T>
	bool is() const {
		return (dynamic_cast<const T *>(this) != NULL);
	}
};

struct C : auto_typeid {};

template<class T>
void f()
{
    C c;
    c.is<C>();
}

void g()
{
    C c;
    c.is<C>();
}

int main()
{
}



# 1 "g++t.cpp"

# 1 "/usr/lib/gcc-lib/sparc-linux/2.95.2/include/typeinfo" 1 3
 
 




#pragma interface "typeinfo"

# 1 "/usr/lib/gcc-lib/sparc-linux/2.95.2/include/exception" 1 3
 
 




#pragma interface "exception"

extern "C++" {

namespace std {

class exception {
public:
  exception () { }
  virtual ~exception () { }
  virtual const char* what () const;
};

class bad_exception : public exception {
public:
  bad_exception () { }
  virtual ~bad_exception () { }
};

typedef void (*terminate_handler) ();
typedef void (*unexpected_handler) ();

terminate_handler set_terminate (terminate_handler);
void terminate () __attribute__ ((__noreturn__));
unexpected_handler set_unexpected (unexpected_handler);
void unexpected () __attribute__ ((__noreturn__));
bool uncaught_exception ();

}  

}  


# 9 "/usr/lib/gcc-lib/sparc-linux/2.95.2/include/typeinfo" 2 3


extern "C++" {

namespace std {

class type_info {
private:
   
  type_info& operator= (const type_info&);
  type_info (const type_info&);

protected:
  explicit type_info (const char *n): _name (n) { }

  const char *_name;

public:
   
  virtual ~type_info ();
    
  bool before (const type_info& arg) const;
  const char* name () const
    { return _name; }
  bool operator== (const type_info& arg) const;
  bool operator!= (const type_info& arg) const;
};

inline bool type_info::
operator!= (const type_info& arg) const
{
  return !operator== (arg);
}

class bad_cast : public exception {
public:
  bad_cast() { }
  virtual ~bad_cast() { }
};

class bad_typeid : public exception {
 public:
  bad_typeid () { }
  virtual ~bad_typeid () { }
};

}  

}  

# 2 "g++t.cpp" 2

# 1 "/usr/lib/gcc-lib/sparc-linux/2.95.2/../../../../include/g++-3/cstddef" 1 3
 
 



# 1 "/usr/lib/gcc-lib/sparc-linux/2.95.2/include/stddef.h" 1 3






 







 

 




 


 





 


# 61 "/usr/lib/gcc-lib/sparc-linux/2.95.2/include/stddef.h" 3


 





 


















 





 

 





















typedef int  ptrdiff_t;









 




 

 


































typedef unsigned int  size_t;






















 




 





























 



















































typedef unsigned int  wint_t;




 

 

# 317 "/usr/lib/gcc-lib/sparc-linux/2.95.2/include/stddef.h" 3




 













 







# 6 "/usr/lib/gcc-lib/sparc-linux/2.95.2/../../../../include/g++-3/cstddef" 2 3


# 3 "g++t.cpp" 2

using namespace std;

struct auto_typeid 
{
	virtual void __never_use_me() {}
	template<class T>
	bool is() const {
		return (dynamic_cast<const T *>(this) != __null );
	}
};

struct C : auto_typeid {};

template<class T>
void f()
{
    C c;
    c.is<C>();
}

void g()
{
    C c;
    c.is<C>();
}

int main()
{
}



Reading specs from /usr/lib/gcc-lib/sparc-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)
 /usr/lib/gcc-lib/sparc-linux/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D_LONGLONG -D__sparc__ -Dlinux -D__sparc -Dsparc -D__ELF__ -D__unix__ -D_LONGLONG -D__sparc__ -D__linux__ -D__sparc -D__sparc__ -D__unix -D__linux -D__sparc -Asystem(unix) -Asystem(posix) -D__EXCEPTIONS -D__SIZE_TYPE__=unsigned int -D__PTRDIFF_TYPE__=int -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) g++t.cpp g++t.ii
GNU CPP version 2.95.2 20000220 (Debian GNU/Linux) (sparc 32/64 GNU/Linux with ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-lib/sparc-linux/2.95.2/../../../../include/g++-3
 /usr/local/include
 /usr/lib/gcc-lib/sparc-linux/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/lib/gcc-lib/sparc-linux/2.95.2/../../../../sparc-linux/include
End of omitted list.
 /usr/lib/gcc-lib/sparc-linux/2.95.2/cc1plus g++t.ii -quiet -dumpbase g++t.cc -version -o g++t.s
GNU C++ version 2.95.2 20000220 (Debian GNU/Linux) (sparc-linux) compiled by GNU C version 2.95.2 20000220 (Debian GNU/Linux).
g++t.cpp: In function `void f()':
g++t.cpp:21: parse error before `>'

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