.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
gcc bug ?
Old
  (#1)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default gcc bug ? - 01-09-2004

very complicated error. Maybe someone here has enough C++ knowledge

problem.cpp
Code:
namespace util { 
	class CSys 
	{ 
	public: 
	CSys(void); 
	~CSys(void); 
	int operator() () {return 8;} 
	}; 

	CSys sys1; 
	CSys &sys=sys1;
} 

util::CSys::CSys()
{
}

util::CSys::~CSys()
{
}

void this_cause_error()
{
	util::sys(); // error in gcc : "error, cannot be used as a fuction" 
}

using namespace util; 

int main(int /* argc */, char* /* argv[] */) 
{ 
	// these 5 lines will call same operator
	util::sys.operator() (); // OK 
	sys.operator() (); // OK 
	sys(); // OK 

	this_cause_error();
	util::sys(); // error in gcc : "error, cannot be used as a fuction" 
}
in Visual C++ .NET, everything is fine, but gcc won't even compile, because of util::sys();

Seems like specifying namespace is causing him trouble, because other 2 lines compile without error

I'm using gcc 3.3.4.
Am I doing something wrong or gcc has a bug ?

EDIT : Well newest gcc is 3.4.1, so maybe I should upgrade, but I just want to know if problem is in gcc or in my code


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)

Last edited by koraX; 01-09-2004 at 10:44..
  
Reply With Quote
Re: gcc bug ?
Old
  (#2)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: gcc bug ? - 01-09-2004

my gcc 3.2 (mingw) compiles this code without problem
I'll start GNU/Linux and try with gcc 2.95 and 3.4.3 now...

Edit in GNU/Linux: Yes you can just update to gcc 3.4.1 and the program will be solved...
gcc 2.95 also has this bug. Also the "3.4.3" is a typo

Last edited by Whistler; 01-09-2004 at 11:10..
  
Reply With Quote
Re: gcc bug ?
Old
  (#3)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: gcc bug ? - 01-09-2004

here is report from gcc :

gcc -v -save-temps problem.cpp

Reading specs from /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/specs
Configured with: ../gcc-3.3.4/configure --prefix=/usr --enable-shared --enable-t
hreads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --
target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.3.4
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/cc1plus -E -D__GNUG__=3 -quiet -v -
D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 -D_GNU_SOURCE problem.cpp
problem.ii
ignoring nonexistent directory "/usr/i486-slackware-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3.4
/usr/include/c++/3.3.4/i486-slackware-linux
/usr/include/c++/3.3.4/backward
/usr/local/include
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/cc1plus -fpreprocessed problem.ii -
quiet -dumpbase problem.cpp -auxbase problem -version -o problem.s
GNU C++ version 3.3.4 (i486-slackware-linux)
compiled by GNU C version 3.3.4.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128570
problem.cpp: In function `void this_cause_error()':
problem.cpp:25: error: `util::sys' cannot be used as a function
problem.cpp: In function `int main(int, char*)':
problem.cpp:38: error: `util::sys' cannot be used as a function


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Re: gcc bug ?
Old
  (#4)
mirv
Super Moderator
 
mirv's Avatar
 
Status: Offline
Posts: 152
Join Date: Apr 2004
Default Re: gcc bug ? - 01-09-2004

By using util::sys() the compiler thinks you're trying to call a function [sys] in namespace util. The only thing it can match it against is a variable - hence the compiler output. If some variations of the compiler pick it up as a variable first, then it will still compile - the but the code is ambiguous in this respect and so should be changed anyway.

Also unless you mean to use things like operator overloading (+, -, *, /, etc) with a class, you should probably try and avoid the name "operator" for a function, as it may also cause a few complications.


mirv the Silly Fish.
  
Reply With Quote
Re: gcc bug ?
Old
  (#5)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: gcc bug ? - 01-09-2004

Quote:
Originally Posted by mirv
Also unless you mean to use things like operator overloading (+, -, *, /, etc) with a class, you should probably try and avoid the name "operator" for a function, as it may also cause a few complications.
Well my problem was whole about operator overloading.
Code:
int operator() () {return 8;}
operator() is operator. It is very nice operator, you can work with class as if it was function. Another cool operator is opeartor bool(), which allows you to include your class in if statements...


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com