Bug 43352 - keyword 'and' defined when even in the absence of iso646
Summary: keyword 'and' defined when even in the absence of iso646
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.1
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-13 03:54 UTC by Mark Jones
Modified: 2010-03-13 04:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Example code (78 bytes, text/plain)
2010-03-13 03:58 UTC, Mark Jones
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Jones 2010-03-13 03:54:02 UTC
========= test.cpp ==========
#include <string>

std::string and(" AND ");

#ifdef and
#undef and
#endif
#define and

======== error msgs =============
test.cpp:5:8: error: "and" cannot be used as a macro name as it is an operator in C++
test.cpp:8:9: error: "and" cannot be used as a macro name as it is an operator in C++
test.cpp:3: error: expected unqualified-id before â&&â token


Several comments along this theme.
http://stackoverflow.com/questions/2419805/when-did-and-become-an-operator-in-c
http://en.wikipedia.org/wiki/Iso646.h
Comment 1 Mark Jones 2010-03-13 03:58:16 UTC
Created attachment 20098 [details]
Example code

compile with 

g++ test.cpp
Comment 2 pinskia@gmail.com 2010-03-13 03:59:09 UTC
Subject: Re:   New: keyword 'and' defined when even in the absence of iso646



Sent from my iPhone

On Mar 12, 2010, at 7:54 PM, "mdjones0978-gcc at yahoo dot com" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> ========= test.cpp ==========
> #include <string>
>
> std::string and(" AND ");
>
> #ifdef and
> #undef and
> #endif
> #define and
>
> ======== error msgs =============
> test.cpp:5:8: error: "and" cannot be used as a macro name as it is  
> an operator
> in C++
> test.cpp:8:9: error: "and" cannot be used as a macro name as it is  
> an operator
> in C++
> test.cpp:3: error: expected unqualified-id before â&&â token
>
>
> Several comments along this theme.
> http://stackoverflow.com/questions/2419805/when-did-and-become-an-operator-in-c
> http://en.wikipedia.org/wiki/Iso646.h
>

C++ is not C. The C++ standard says these are keywords and not defines  
which is unlike the C standard.




>
> -- 
>           Summary: keyword 'and' defined when even in the absence of  
> iso646
>           Product: gcc
>           Version: 4.4.1
>            Status: UNCONFIRMED
>          Severity: minor
>          Priority: P3
>         Component: c++
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: mdjones0978-gcc at yahoo dot com
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43352
>
Comment 3 Mark Jones 2010-03-13 03:59:41 UTC
g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
Linux 2.6.31-20-generic #57-Ubuntu SMP Mon Feb 8 09:05:19 UTC 2010 i686 GNU/Linux
Comment 4 Andrew Pinski 2010-03-13 04:37:42 UTC
Use -fno-operator-names if you want these keywords not to be keywords in C++.  Closing as invalid because these are keywords in C++.