Why does GCC Preprocessor NOT support such macro?

2009-10-23 Thread Zhang Lin
Hello,
I have encountered an issue when building ACE with MinGW and GCC 4.4.1
The following macro was not accepted by the preprocessor and it reported such 
an error: "error: operator '==' has no left operand".

#if !defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER)
# define ACE_HAS_NONSTATIC_OBJECT_MANAGER
#elif (ACE_HAS_NONSTATIC_OBJECT_MANAGER == 0)
# undef ACE_HAS_NONSTATIC_OBJECT_MANAGER
#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */

As I think, since ACE_HAS_NONSTATIC_OBJECT_MANAGER isn't defined, the #elif 
branch should not be processed.
This macro is accepted by VC7.1 and Sun Studio 12.

Thanks.

Best Regards,
Lin Zhang
2009-10-23

Re: Why does GCC Preprocessor NOT support such macro?

2009-10-23 Thread Zhang Lin
Sorry, maybe my  representation is not quite clear.
I mean that I didn't define ACE_HAS_NONSTATIC_OBJECT_MANAGER at all, so the 
preprocesser should not process "#elif (ACE_HAS_NONSTATIC_OBJECT_MANAGER == 
0)", the following simple cpp can reproduce the problem.

Test.cpp
==
#if !defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER)
# define ACE_HAS_NONSTATIC_OBJECT_MANAGER
#elif (ACE_HAS_NONSTATIC_OBJECT_MANAGER == 0)
# undef ACE_HAS_NONSTATIC_OBJECT_MANAGER
#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */

int main(int argc, char *argv[])
{
 return 0;
}
==

the compile command is:
gcc -Wall -o "Test.exe" "Test.cpp" -lstdc++ -s

and the error message is:
Test.cpp:3:41: error: operator '==' has no left operand


- Original Message - 
From: "John Graham" 
To: 
Sent: Friday, October 23, 2009 10:03 PM
Subject: Re: Why does GCC Preprocessor NOT support such macro?


> 2009/10/23 Zhang Lin :
> > Hello,
> > I have encountered an issue when building ACE with MinGW and GCC 4.4.1
> > The following macro was not accepted by the preprocessor and it reported 
> > such an error: "error: operator '==' has no left operand".
> >
> > #if !defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER)
> > # define ACE_HAS_NONSTATIC_OBJECT_MANAGER
> > #elif (ACE_HAS_NONSTATIC_OBJECT_MANAGER == 0)
> > # undef ACE_HAS_NONSTATIC_OBJECT_MANAGER
> > #endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */
> >
> > As I think, since ACE_HAS_NONSTATIC_OBJECT_MANAGER isn't defined, the #elif 
> > branch should not be processed.
> > This macro is accepted by VC7.1 and Sun Studio 12.
> >
> > Thanks.
> >
> > Best Regards,
> > Lin Zhang
> > 2009-10-23
> 
> You'll get this error if ACE_HAS_NONSTATIC_OBJECT_MANAGER is defined,
> but has a null value - i.e. if somewhere before it was:
> 
> #define ACE_HAS_NONSTATIC_OBJECT_MANAGER
> 
> and not:
> 
> #define ACE_HAS_NONSTATIC_OBJECT_MANAGER 1
> 
> (for example)
> 
> I'm not sure if there's a way to test for a macro being null, but if
> you change your previous declarations to defining it so something
> instead of nothing, everything should be dandy.
> 
> John G
> 

A forward declaration used by template class issue on gcc 4.4.1

2009-10-23 Thread Zhang Lin
Hello,
I have encountered an issue when building ACE with MinGW and GCC 4.4.1.
The following example can reproduce the issue:
==
main.cpp
==
class ACE_Message_Queue_NT;

template
class ACE_Message_Queue_Factory
{
public:
 static ACE_Message_Queue_NT *create_NT_message_queue (int max_threads);
};

template 
ACE_Message_Queue_NT *ACE_Message_Queue_Factory::create_NT_message_queue 
(int max_threads)
{
 ACE_Message_Queue_NT *tmp = 0;

 tmp = new ACE_Message_Queue_NT (max_threads);

 return tmp;
}

class ACE_Message_Queue_NT
{
public:
 ACE_Message_Queue_NT (int)
 {
 }
};

int main(void)
{
 ACE_Message_Queue_Factory::create_NT_message_queue(100);

 return 0;
}

This code can be accepted by Microsoft VC 7.1, but GCC reported the following 
error:
main.cpp: In static member function 'static ACE_Message_Queue_NT* 
ACE_Message_Queue_Factory::create_NT_message_queue(int)':
main.cpp:15: error: invalid use of incomplete type 'struct ACE_Message_Queue_NT'
main.cpp:1: error: forward declaration of 'struct ACE_Message_Queue_NT'

Is there any description about the error above in C++ standard?

Thanks.

Best Regards,
Lin Zhang
2009-10-24