Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit b35e369

Browse files
zodiac403Cylix
authored andcommitted
Resolve Compiler Warnings for Windows Build (#129)
* MSVC: Use same 'PlatformToolset' for all build configurations. * MSVC warnings - Enable `TreatWarningsAsErrors` for compiler and linker. - Resolve compiler warnings (possible loss of data).
1 parent f494ab3 commit b35e369

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

includes/cpp_redis/misc/macro.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2015-2017 Simon Ninon <[email protected]>
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
#pragma once
24+
25+
#if _WIN32
26+
#define __CPP_REDIS_LENGTH(size) static_cast<unsigned int>(size) // for Windows, convert size to `unsigned int`
27+
#else /* _WIN32 */
28+
#define __CPP_REDIS_LENGTH(size) size // for Unix, keep size as `size_t`
29+
#endif /* _WIN32 */

msvc15/cpp_redis.vcxproj

+21-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ SOFTWARE.
7676
<ClInclude Include="..\includes\cpp_redis\helpers\variadic_template.hpp" />
7777
<ClInclude Include="..\includes\cpp_redis\misc\error.hpp" />
7878
<ClInclude Include="..\includes\cpp_redis\misc\logger.hpp" />
79+
<ClInclude Include="..\includes\cpp_redis\misc\macro.hpp" />
7980
<ClInclude Include="..\includes\cpp_redis\network\redis_connection.hpp" />
8081
<ClInclude Include="..\includes\cpp_redis\network\tcp_client.hpp" />
8182
<ClInclude Include="..\includes\cpp_redis\network\tcp_client_iface.hpp" />
@@ -91,13 +92,13 @@ SOFTWARE.
9192
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
9293
<ConfigurationType>StaticLibrary</ConfigurationType>
9394
<UseDebugLibraries>true</UseDebugLibraries>
94-
<PlatformToolset>v141</PlatformToolset>
95+
<PlatformToolset>v140</PlatformToolset>
9596
<CharacterSet>Unicode</CharacterSet>
9697
</PropertyGroup>
9798
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
9899
<ConfigurationType>StaticLibrary</ConfigurationType>
99100
<UseDebugLibraries>false</UseDebugLibraries>
100-
<PlatformToolset>v141</PlatformToolset>
101+
<PlatformToolset>v140</PlatformToolset>
101102
<WholeProgramOptimization>true</WholeProgramOptimization>
102103
<CharacterSet>Unicode</CharacterSet>
103104
</PropertyGroup>
@@ -110,7 +111,7 @@ SOFTWARE.
110111
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
111112
<ConfigurationType>StaticLibrary</ConfigurationType>
112113
<UseDebugLibraries>false</UseDebugLibraries>
113-
<PlatformToolset>v141</PlatformToolset>
114+
<PlatformToolset>v140</PlatformToolset>
114115
<WholeProgramOptimization>true</WholeProgramOptimization>
115116
<CharacterSet>Unicode</CharacterSet>
116117
</PropertyGroup>
@@ -148,10 +149,14 @@ SOFTWARE.
148149
<Optimization>Disabled</Optimization>
149150
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
150151
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
152+
<TreatWarningAsError>true</TreatWarningAsError>
151153
</ClCompile>
152154
<Link>
153155
<SubSystem>Windows</SubSystem>
154156
</Link>
157+
<Lib>
158+
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
159+
</Lib>
155160
</ItemDefinitionGroup>
156161
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
157162
<ClCompile>
@@ -162,10 +167,14 @@ SOFTWARE.
162167
<PreprocessorDefinitions>_DEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
163168
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
164169
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
170+
<TreatWarningAsError>true</TreatWarningAsError>
165171
</ClCompile>
166172
<Link>
167173
<SubSystem>Windows</SubSystem>
168174
</Link>
175+
<Lib>
176+
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
177+
</Lib>
169178
</ItemDefinitionGroup>
170179
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
171180
<ClCompile>
@@ -177,12 +186,16 @@ SOFTWARE.
177186
<IntrinsicFunctions>true</IntrinsicFunctions>
178187
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
179188
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
189+
<TreatWarningAsError>true</TreatWarningAsError>
180190
</ClCompile>
181191
<Link>
182192
<SubSystem>Windows</SubSystem>
183193
<EnableCOMDATFolding>true</EnableCOMDATFolding>
184194
<OptimizeReferences>true</OptimizeReferences>
185195
</Link>
196+
<Lib>
197+
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
198+
</Lib>
186199
</ItemDefinitionGroup>
187200
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
188201
<ClCompile>
@@ -194,14 +207,18 @@ SOFTWARE.
194207
<IntrinsicFunctions>true</IntrinsicFunctions>
195208
<PreprocessorDefinitions>NDEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
196209
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
210+
<TreatWarningAsError>true</TreatWarningAsError>
197211
</ClCompile>
198212
<Link>
199213
<SubSystem>Windows</SubSystem>
200214
<EnableCOMDATFolding>true</EnableCOMDATFolding>
201215
<OptimizeReferences>true</OptimizeReferences>
202216
</Link>
217+
<Lib>
218+
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
219+
</Lib>
203220
</ItemDefinitionGroup>
204221
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
205222
<ImportGroup Label="ExtensionTargets">
206223
</ImportGroup>
207-
</Project>
224+
</Project>

msvc15/cpp_redis.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,8 @@ SOFTWARE.
176176
<ClInclude Include="..\includes\cpp_redis\network\tcp_client_iface.hpp">
177177
<Filter>Header Files\cpp_redis\network</Filter>
178178
</ClInclude>
179+
<ClInclude Include="..\includes\cpp_redis\misc\macro.hpp">
180+
<Filter>Header Files\cpp_redis\misc</Filter>
181+
</ClInclude>
179182
</ItemGroup>
180183
</Project>

sources/core/client.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <cpp_redis/core/client.hpp>
2424
#include <cpp_redis/misc/error.hpp>
25+
#include <cpp_redis/misc/macro.hpp>
2526

2627
namespace cpp_redis {
2728

@@ -257,7 +258,7 @@ client::clear_callbacks(void) {
257258
//! dequeue commands and move them to a local variable
258259
std::queue<command_request> commands = std::move(m_commands);
259260

260-
m_callbacks_running += commands.size();
261+
m_callbacks_running += __CPP_REDIS_LENGTH(commands.size());
261262

262263
std::thread t([=]() mutable {
263264
while (!commands.empty()) {

sources/network/tcp_client.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23+
#include <cpp_redis/misc/macro.hpp>
2324
#include <cpp_redis/network/tcp_client.hpp>
2425

2526
namespace cpp_redis {
@@ -82,7 +83,7 @@ tcp_client::set_on_disconnection_handler(const disconnection_handler_t& disconne
8283

8384
void
8485
set_default_nb_workers(std::size_t nb_threads) {
85-
tacopie::get_default_io_service(nb_threads);
86+
tacopie::get_default_io_service(__CPP_REDIS_LENGTH(nb_threads));
8687
}
8788

8889
} // namespace network

0 commit comments

Comments
 (0)