This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Non-Critical Compiler WARNING: Python Embedding C++11 does not allow non-constant string literals
Type: compile error Stage: resolved
Components: Extension Modules Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Daniel Lord, vstinner
Priority: normal Keywords:

Created on 2016-07-16 17:05 by Daniel Lord, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg270572 - (view) Author: Daniel Lord (Daniel Lord) Date: 2016-07-16 17:05
ERROR SUMMARY:
abstract.h:1332:60: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)

ISSUE CRITICALITY:
Non-fatal Warning (will become an error eventually when deprecations expire and errors are introduced in c++XX or later)

COMPILER:
g++ -std=c++11
g++ 4.2.1

$g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

FILE:
abstract.h

WORKAROUND:
add compiler option: -Wc++11-compat-deprecated-writable-strings and -Wwritable-strings. In theory anyway: doesn't seem to work (still get the warning) and when I tried g++ 5.3.0, the compiler marks that option as an error and unsupported.

g++-5.3.0: error: unrecognized command line option ‘-Wwritable-strings’
g++-5.3.0: error: unrecognized command line option ‘-Wc++11-compat-deprecated-writable-strings’

ERROR MESSAGE:
warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
        pList = PyMapping_Keys(pDict);
                ^
/Users/xxxxxx/anaconda/include/python2.7/abstract.h:1332:49: note: expanded from macro 'PyMapping_Keys'
#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
                                                ^
1 warning generated.

OFFENDING STATEMNT:
#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)

PROBLEM:
"keys" is a string literal but not declared as a constant.

COMMENTS:
This is not a big deal...yet.
I can compile with g++ C++11 using the above flag to allow deprecated writeable string literals for my application embedding Python 2.7.
However, I assume the embedding code is replete with non-constant string literals which eventually need to be fixed though this is the first one I have run into.
msg355202 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-23 00:38
This issues has been fixed in Python 3: the second parameter of PyObject_CallMethod() is now a "const char*". Please upgrade to Python 3.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71717
2019-10-23 00:38:54vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg355202

resolution: fixed
stage: resolved
2016-07-16 17:05:44Daniel Lordcreate