From e7bc8501b785c77055dcd6ca27e5edcd0d9c41c9 Mon Sep 17 00:00:00 2001 From: Stephan Linz Date: Mon, 28 Nov 2016 17:48:44 +0100 Subject: [PATCH] avoid conversion from string constant to 'char*' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Warning was (gcc): .../examples/LibusbTest.cpp: In function ‘int main(int, char**)’: .../examples/LibusbTest.cpp:481:82: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] std::shared_ptr pPingString = allocString("PING!", pingDataSize); ^ .../examples/LibusbTest.cpp:625:84: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] std::shared_ptr pPingString = allocString("apostle", pingDataSize); ^ .../examples/LibusbTest.cpp:768:84: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] std::shared_ptr pPingString = allocString("apostle", pingDataSize); ^ Warning was (clang): .../examples/LibusbTest.cpp:481:61: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings] ...std::shared_ptr pPingString = allocString("PING!", pingDa... ^ .../examples/LibusbTest.cpp:625:61: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings] ...std::shared_ptr pPingString = allocString("apostle", ping... ^ .../examples/LibusbTest.cpp:768:61: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings] ...std::shared_ptr pPingString = allocString("apostle", ping... ^ Related-to-issue: #2 Signed-off-by: Stephan Linz --- examples/LibusbTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/LibusbTest.cpp b/examples/LibusbTest.cpp index e3e0da0..1bb7e9c 100644 --- a/examples/LibusbTest.cpp +++ b/examples/LibusbTest.cpp @@ -29,10 +29,10 @@ // Utility functions /// Creates a std::shared_ptr containing a wide string. (demo) - std::shared_ptr allocWString(wchar_t* pString, size_t& outSize); + std::shared_ptr allocWString(const wchar_t* pString, size_t& outSize); /// Creates a std::shared_ptr containing a string. (demo) - std::shared_ptr allocString(char* pString, size_t& outSize); + std::shared_ptr allocString(const char* pString, size_t& outSize); // Test results @@ -914,7 +914,7 @@ int main(int argc, char* argv[]) return failBit ? EXIT_FAILURE : EXIT_SUCCESS; } -std::shared_ptr allocWString( wchar_t* pString, size_t& outSize ) +std::shared_ptr allocWString( const wchar_t* pString, size_t& outSize ) { size_t strSize = wcslen(pString); @@ -929,7 +929,7 @@ std::shared_ptr allocWString( wchar_t* pString, size_t& outSize ) } -std::shared_ptr allocString( char* pString, size_t& outSize ) +std::shared_ptr allocString( const char* pString, size_t& outSize ) { size_t strSize = strlen(pString);