php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
Submitted: 2013-10-31 10:17 UTC Modified: 2014-01-04 00:49 UTC
From: pvasilevich at parallels dot com Assigned: ab (profile)
Status: Closed Package: Compile Failure
PHP Version: 5.5.5 OS: Windows
Private report: No CVE-ID: None
 [2013-10-31 10:17 UTC] pvasilevich at parallels dot com
Description:
------------
Suppose you have an PHP extension that uses C++ standard library.

one of source files looks like:

#ifdef __cplusplus
extern "C" {
#endif

#include "php.h"

#ifdef __cplusplus
}
#endif

#include <string>
...


After trying to compile this extension using Visual Studio 2012 you got the following error:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xkeycheck.h(242): fatal error C1189: #error :  The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.

Documentation for Visual Studio says:
http://msdn.microsoft.com/en-us/libraRy/bb531344%28v=vs.110%29.aspx

C++11 17.6.4.3.1 [macro.names]/2 forbids macro-izing keywords when C++ Standard Library headers are included. The headers now emit compiler errors if they detect macro-ized keywords. (Defining _ALLOW_KEYWORD_MACROS allows such code to compile, but we strongly discourage that usage.)


This problem appeared because of the following code in PHP:

\TSRM\tsrm_config.w32.h
\Zend\zend_config.w32.h

#undef inline
#ifdef ZEND_WIN32_FORCE_INLINE
# define inline __forceinline
#else
# define inline
#endif


Redefinition of keywords is forbidden in C++11 standard.

Possible workaround is to use keyword provided by Microsoft:

#define _ALLOW_KEYWORD_MACROS

But this is not enough because in this case macro inline will be defined as empty, bringing problems in other code compilation (those functions that were defined as inline are not inline anymore), for example:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\ostream(1020): error C2491: 'std::endl' : definition of dllimport function not allowed


Possible workaround for now is to define both:

#define _ALLOW_KEYWORD_MACROS
#define ZEND_WIN32_FORCE_INLINE

Could you please resolve this issue somehow, for example by changing your define as follows:

#ifdef ZEND_WIN32_FORCE_INLINE
# undef inline
# define inline __forceinline
#endif

or wrap it using other #ifdef to be able to stop redefining of inline macro in PHP code.


Test script:
---------------
#ifdef __cplusplus
extern "C" {
#endif

#include "php.h"

#ifdef __cplusplus
}
#endif

#include <string>
...


Expected result:
----------------
There is no redefinition of standard keyword "inline" in PHP code.



Actual result:
--------------
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xkeycheck.h(242): fatal error C1189: #error :  The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-02 13:55 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2014-01-04 00:42 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae1cc83f98b779eb3f01779d416bde994332efd3
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-04 00:42 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2014-01-04 00:42 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4e7c9ea896e7aab8129701c7a0ddfbbab5b0f36a
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-04 00:42 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19aafe43b27b52be6a006c652bbefd936bd3721c
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-04 00:49 UTC] ab@php.net
Please define ZEND_WIN32_KEEP_INLINE in your config.w32 or in the source before including any Zend headers, that'll fix the issue in debug mode. For versions after 5.5.7 of course. The ZEND_WIN32_FORCE_INLINE def is automatically appended in release mode, in that case _ALLOW_KEYWORD_MACROS will be defined in zend_config.w32.h .

Thanks.
 [2014-01-04 01:28 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19aafe43b27b52be6a006c652bbefd936bd3721c
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-05 18:23 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae1cc83f98b779eb3f01779d416bde994332efd3
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-05 18:23 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4e7c9ea896e7aab8129701c7a0ddfbbab5b0f36a
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-05 22:06 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4e7c9ea896e7aab8129701c7a0ddfbbab5b0f36a
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-05 22:06 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae1cc83f98b779eb3f01779d416bde994332efd3
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-01-17 21:59 UTC] bwoebi@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19aafe43b27b52be6a006c652bbefd936bd3721c
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2014-02-06 08:43 UTC] bwoebi@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19aafe43b27b52be6a006c652bbefd936bd3721c
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19aafe43b27b52be6a006c652bbefd936bd3721c
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC