.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   gcc bug ? (http://forums.bots-united.com/showthread.php?t=2582)

koraX 01-09-2004 10:31

gcc bug ?
 
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

Whistler 01-09-2004 10:54

Re: gcc bug ?
 
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

koraX 01-09-2004 11:01

Re: gcc bug ?
 
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

mirv 01-09-2004 15:17

Re: gcc bug ?
 
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.

koraX 01-09-2004 16:17

Re: gcc bug ?
 
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...


All times are GMT +2. The time now is 23:49.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.