public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Why does GCC Preprocessor NOT support such macro?
@ 2009-10-23 14:05 Zhang Lin
  2009-10-23 14:15 ` John Graham
  2009-10-27 22:55 ` Jakub Jelinek
  0 siblings, 2 replies; 6+ messages in thread
From: Zhang Lin @ 2009-10-23 14:05 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why does GCC Preprocessor NOT support such macro?
  2009-10-23 14:05 Why does GCC Preprocessor NOT support such macro? Zhang Lin
@ 2009-10-23 14:15 ` John Graham
  2009-10-23 18:21   ` Zhang Lin
  2009-10-27 22:55 ` Jakub Jelinek
  1 sibling, 1 reply; 6+ messages in thread
From: John Graham @ 2009-10-23 14:15 UTC (permalink / raw)
  To: gcc

2009/10/23 Zhang Lin <zhanglin0714@163.com>:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why does GCC Preprocessor NOT support such macro?
  2009-10-23 14:15 ` John Graham
@ 2009-10-23 18:21   ` Zhang Lin
  2009-10-23 21:56     ` Jean Christophe Beyler
  2009-10-23 22:46     ` Andrew Pinski
  0 siblings, 2 replies; 6+ messages in thread
From: Zhang Lin @ 2009-10-23 18:21 UTC (permalink / raw)
  To: John Graham; +Cc: gcc

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" <johngavingraham@googlemail.com>
To: <gcc@gcc.gnu.org>
Sent: Friday, October 23, 2009 10:03 PM
Subject: Re: Why does GCC Preprocessor NOT support such macro?


> 2009/10/23 Zhang Lin <zhanglin0714@163.com>:
> > 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
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why does GCC Preprocessor NOT support such macro?
  2009-10-23 18:21   ` Zhang Lin
@ 2009-10-23 21:56     ` Jean Christophe Beyler
  2009-10-23 22:46     ` Andrew Pinski
  1 sibling, 0 replies; 6+ messages in thread
From: Jean Christophe Beyler @ 2009-10-23 21:56 UTC (permalink / raw)
  To: Zhang Lin; +Cc: John Graham, gcc

It works no problem for me.

This is what I get:

$ gcc -Wall -o "Test.exe" "macro.cpp" -lstdc++ -s -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --enable-compiler=c --enable-language=c
--prefix=/home/beyler/tmp/gcc-4.3.2/bin
Thread model: posix
gcc version 4.3.2 (GCC)
COLLECT_GCC_OPTIONS='-Wall' '-o' 'Test.exe' '-s' '-v' '-mtune=generic'
 /home/beyler/tmp/gcc-4.3.2/bin/libexec/gcc/i686-pc-linux-gnu/4.3.2/cc1plus
-quiet -v -D_GNU_SOURCE macro.cpp -quiet -dumpbase macro.cpp
-mtune=generic -auxbase macro -Wall -version -o /tmp/ccx2HphX.s
ignoring nonexistent directory
"/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../../include/c++/4.3.2
 /home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../../include/c++/4.3.2/i686-pc-linux-gnu
 /home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../../include/c++/4.3.2/backward
 /usr/local/include
 /home/beyler/tmp/gcc-4.3.2/bin/include
 /home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/include
 /home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.3.2 (i686-pc-linux-gnu)
        compiled by GNU C version 4.3.2, GMP version 4.2.2, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 80f643acb5e6c86441cd11d3ee5d089a
COLLECT_GCC_OPTIONS='-Wall' '-o' 'Test.exe' '-s' '-v' '-mtune=generic'
 as -V -Qy -o /tmp/cccKZT5N.o /tmp/ccx2HphX.s
GNU assembler version 2.18.93 (i486-linux-gnu) using BFD version (GNU
Binutils for Ubuntu) 2.18.93.20081009
COMPILER_PATH=/home/beyler/tmp/gcc-4.3.2/bin/libexec/gcc/i686-pc-linux-gnu/4.3.2/:/home/beyler/tmp/gcc-4.3.2/bin/libexec/gcc/i686-pc-linux-gnu/4.3.2/:/home/beyler/tmp/gcc-4.3.2/bin/libexec/gcc/i686-pc-linux-gnu/:/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/:/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/
LIBRARY_PATH=/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/:/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-Wall' '-o' 'Test.exe' '-s' '-v' '-mtune=generic'
 /home/beyler/tmp/gcc-4.3.2/bin/libexec/gcc/i686-pc-linux-gnu/4.3.2/collect2
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o
Test.exe -s /usr/lib/crt1.o /usr/lib/crti.o
/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/crtbegin.o
-L/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2
-L/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/../../..
/tmp/cccKZT5N.o -lstdc++ -lgcc --as-needed -lgcc_s --no-as-needed -lc
-lgcc --as-needed -lgcc_s --no-as-needed
/home/beyler/tmp/gcc-4.3.2/bin/lib/gcc/i686-pc-linux-gnu/4.3.2/crtend.o
/usr/lib/crtn.o


On Fri, Oct 23, 2009 at 12:35 PM, Zhang Lin <zhanglin0714@163.com> wrote:
> 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" <johngavingraham@googlemail.com>
> To: <gcc@gcc.gnu.org>
> Sent: Friday, October 23, 2009 10:03 PM
> Subject: Re: Why does GCC Preprocessor NOT support such macro?
>
>
>> 2009/10/23 Zhang Lin <zhanglin0714@163.com>:
>> > 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
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why does GCC Preprocessor NOT support such macro?
  2009-10-23 18:21   ` Zhang Lin
  2009-10-23 21:56     ` Jean Christophe Beyler
@ 2009-10-23 22:46     ` Andrew Pinski
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Pinski @ 2009-10-23 22:46 UTC (permalink / raw)
  To: Zhang Lin; +Cc: John Graham, gcc

On Fri, Oct 23, 2009 at 9:35 AM, Zhang Lin <zhanglin0714@163.com> wrote:
> 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.


See bug 36453 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36453>,
this code is invalid.

Anyways this is offtopic for this mailing list, next time send an
email to gcc-help@ for developing with GCC questions.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why does GCC Preprocessor NOT support such macro?
  2009-10-23 14:05 Why does GCC Preprocessor NOT support such macro? Zhang Lin
  2009-10-23 14:15 ` John Graham
@ 2009-10-27 22:55 ` Jakub Jelinek
  1 sibling, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2009-10-27 22:55 UTC (permalink / raw)
  To: Zhang Lin; +Cc: gcc

On Fri, Oct 23, 2009 at 09:58:55PM +0800, Zhang Lin wrote:
> 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.

You are wrong.  The C/C++ standards actually require it to be
constant-expression, ( == 0) is not a valid constant expression.
See http://gcc.gnu.org/PR36320 for details.

> This macro is accepted by VC7.1 and Sun Studio 12.

That doesn't mean this code is not buggy.
Just use
#else
#if ...
...
#endif
instead of
#elif ...
...

	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-10-27 20:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-23 14:05 Why does GCC Preprocessor NOT support such macro? Zhang Lin
2009-10-23 14:15 ` John Graham
2009-10-23 18:21   ` Zhang Lin
2009-10-23 21:56     ` Jean Christophe Beyler
2009-10-23 22:46     ` Andrew Pinski
2009-10-27 22:55 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).