Skip to content

Commit 7d56338

Browse files
authored
Merge pull request #194 from wravery/warning-flags
Enable strict compiler warnings and fix resulting warnings/errors
2 parents 6a06c5a + b65bf15 commit 7d56338

22 files changed

+166
-162
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ cmake_minimum_required(VERSION 3.15)
66
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows: https://cmake.org/cmake/help/latest/policy/CMP0091.html
77
cmake_policy(SET CMP0091 NEW)
88

9+
# Do not set default MSVC warning flags: https://cmake.org/cmake/help/latest/policy/CMP0092.html
10+
cmake_policy(SET CMP0092 NEW)
11+
912
# Default to the last updated version from version.txt.
1013
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.txt" VERSION_FILE)
1114
file(READ "${VERSION_FILE}" LATEST_VERSION)
@@ -52,6 +55,13 @@ if(VCPKG_TARGET_TRIPLET)
5255
endif()
5356
endif()
5457

58+
# Enable more warnings, and treat warnings as errors.
59+
if(MSVC)
60+
add_compile_options(/W4 /WX /permissive-)
61+
else()
62+
add_compile_options(-Wall -Wextra -pedantic -Werror)
63+
endif()
64+
5565
function(add_bigobj_flag target)
5666
if(MSVC)
5767
# MSVC requires the /bigobj flag if the number of sections gets too big.

include/SchemaLoader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct ScalarType
4848
{
4949
std::string_view type;
5050
std::string_view description;
51-
std::string_view specifiedByURL;
51+
std::string_view specifiedByURL {};
5252
};
5353

5454
using ScalarTypeList = std::vector<ScalarType>;
@@ -105,7 +105,7 @@ struct InputType
105105
std::string_view cppType;
106106
InputFieldList fields;
107107
std::string_view description;
108-
std::unordered_set<std::string_view> dependencies;
108+
std::unordered_set<std::string_view> dependencies {};
109109
};
110110

111111
using InputTypeList = std::vector<InputType>;
@@ -298,8 +298,8 @@ class SchemaLoader
298298
void validateImplementedInterfaces() const;
299299
const InterfaceType& findInterfaceType(
300300
std::string_view typeName, std::string_view interfaceName) const;
301-
void validateInterfaceFields(std::string_view typeName,
302-
std::string_view interfaceName, const OutputFieldList& typeFields) const;
301+
void validateInterfaceFields(std::string_view typeName, std::string_view interfaceName,
302+
const OutputFieldList& typeFields) const;
303303
void validateTransitiveInterfaces(
304304
std::string_view typeName, const std::vector<std::string_view>& interfaces) const;
305305

include/graphqlservice/GraphQLService.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ GRAPHQLSERVICE_EXPORT error_path buildErrorPath(const std::optional<field_path>&
7676
struct schema_error
7777
{
7878
std::string message;
79-
schema_location location;
80-
error_path path;
79+
schema_location location {};
80+
error_path path {};
8181
};
8282

8383
GRAPHQLSERVICE_EXPORT response::Value buildErrorValues(std::list<schema_error>&& structuredErrors);
@@ -579,7 +579,7 @@ struct ResolverParams : SelectionSetParams
579579
struct ResolverResult
580580
{
581581
response::Value data;
582-
std::list<schema_error> errors;
582+
std::list<schema_error> errors {};
583583
};
584584

585585
using AwaitableResolver = internal::Awaitable<ResolverResult>;
@@ -1195,10 +1195,10 @@ struct RequestResolveParams
11951195
response::Value variables { response::Type::Map };
11961196

11971197
// Optional async execution awaitable.
1198-
await_async launch;
1198+
await_async launch {};
11991199

12001200
// Optional sub-class of RequestState which will be passed to each resolver and field accessor.
1201-
std::shared_ptr<RequestState> state;
1201+
std::shared_ptr<RequestState> state {};
12021202
};
12031203

12041204
struct RequestSubscribeParams
@@ -1212,10 +1212,10 @@ struct RequestSubscribeParams
12121212
response::Value variables { response::Type::Map };
12131213

12141214
// Optional async execution awaitable.
1215-
await_async launch;
1215+
await_async launch {};
12161216

12171217
// Optional sub-class of RequestState which will be passed to each resolver and field accessor.
1218-
std::shared_ptr<RequestState> state;
1218+
std::shared_ptr<RequestState> state {};
12191219
};
12201220

12211221
struct RequestUnsubscribeParams
@@ -1224,7 +1224,7 @@ struct RequestUnsubscribeParams
12241224
SubscriptionKey key;
12251225

12261226
// Optional async execution awaitable.
1227-
await_async launch;
1227+
await_async launch {};
12281228
};
12291229

12301230
using SubscriptionArguments = std::map<std::string_view, response::Value>;
@@ -1240,7 +1240,7 @@ struct SubscriptionFilter
12401240

12411241
// Optional field directives filter, which can either be a set of required directives and
12421242
// arguments, or a callback which returns true if the directives match custom criteria.
1243-
std::optional<std::variant<Directives, SubscriptionDirectiveFilterCallback>> directives;
1243+
std::optional<std::variant<Directives, SubscriptionDirectiveFilterCallback>> directives {};
12441244
};
12451245

12461246
// Deliver to a specific subscription key, or apply custom criteria for the field name, arguments,
@@ -1254,13 +1254,13 @@ struct RequestDeliverParams
12541254

12551255
// Optional filter to control which subscriptions will receive the event. If not specified,
12561256
// every subscription on this field will receive the event and evaluate their queries.
1257-
RequestDeliverFilter filter;
1257+
RequestDeliverFilter filter {};
12581258

12591259
// Optional async execution awaitable.
1260-
await_async launch;
1260+
await_async launch {};
12611261

12621262
// Optional override for the default Subscription operation object.
1263-
std::shared_ptr<Object> subscriptionObject;
1263+
std::shared_ptr<Object> subscriptionObject {};
12641264
};
12651265

12661266
using TypeMap = internal::string_view_map<std::shared_ptr<Object>>;

samples/today/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ add_library(todaygraphql_nointrospection STATIC TodayMock.cpp)
1515
target_link_libraries(todaygraphql_nointrospection PUBLIC today_nointrospection_schema)
1616
target_include_directories(todaygraphql_nointrospection PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
1717

18+
if(MSVC)
19+
# warning C4702: unreachable code
20+
target_compile_options(todaygraphql PUBLIC /wd4702)
21+
target_compile_options(todaygraphql_nointrospection PUBLIC /wd4702)
22+
endif()
23+
1824
# sample
1925
add_executable(sample sample.cpp)
2026
target_link_libraries(sample PRIVATE

samples/today/TodayMock.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ class Task
262262
response::IdType _id;
263263
std::shared_ptr<const response::Value> _title;
264264
bool _isComplete;
265-
TaskState _state = TaskState::New;
266265
};
267266

268267
class TaskEdge

samples/today/sample.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ int main(int argc, char** argv)
6161

6262
try
6363
{
64-
peg::ast query;
64+
peg::ast ast;
6565

6666
if (argc > 1)
6767
{
68-
query = peg::parseFile(argv[1]);
68+
ast = peg::parseFile(argv[1]);
6969
}
7070
else
7171
{
7272
std::istream_iterator<char> start { std::cin >> std::noskipws }, end {};
7373
std::string input { start, end };
7474

75-
query = peg::parseString(std::move(input));
75+
ast = peg::parseString(std::move(input));
7676
}
7777

78-
if (!query.root)
78+
if (!ast.root)
7979
{
8080
std::cerr << "Unknown error!" << std::endl;
8181
std::cerr << std::endl;
@@ -85,7 +85,7 @@ int main(int argc, char** argv)
8585
std::cout << "Executing query..." << std::endl;
8686

8787
std::cout << response::toJSON(
88-
service->resolve({ query, ((argc > 2) ? argv[2] : "") }).get())
88+
service->resolve({ ast, ((argc > 2) ? argv[2] : "") }).get())
8989
<< std::endl;
9090
}
9191
catch (const std::runtime_error& ex)

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if(GRAPHQL_UPDATE_VERSION)
4242
endif()
4343

4444
if(WIN32)
45-
# Always build the version.rc files with these flags, even if we aren't regnerating them.
45+
# Always build the version.rc files with these flags, even if we aren't regenerating them.
4646
set(CMAKE_RC_FLAGS "/nologo")
4747
set(CMAKE_RC_FLAGS_DEBUG "/dDEBUG")
4848

src/ClientGenerator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
206206
{
207207
pendingSeparator.reset();
208208

209-
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name())
210-
<< R"cpp(
209+
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name()) << R"cpp(
211210
{
212211
)cpp";
213212
for (const auto& enumValue : enumType->enumValues())
@@ -459,15 +458,13 @@ using namespace )cpp"
459458

460459
const auto& enumValues = enumType->enumValues();
461460
const auto cppType = _schemaLoader.getCppType(enumType->name());
462-
bool firstValue = true;
463461

464462
sourceFile << R"cpp(static const std::array<std::string_view, )cpp" << enumValues.size()
465463
<< R"cpp(> s_names)cpp" << cppType << R"cpp( = {
466464
)cpp";
467465

468466
for (const auto& enumValue : enumValues)
469467
{
470-
firstValue = false;
471468
sourceFile << R"cpp( ")cpp" << SchemaLoader::getSafeCppName(enumValue->name())
472469
<< R"cpp("sv,
473470
)cpp";
@@ -485,7 +482,6 @@ using namespace )cpp"
485482
{
486483
pendingSeparator.reset();
487484

488-
const auto& enumValues = enumType->enumValues();
489485
const auto cppType = _schemaLoader.getCppType(enumType->name());
490486

491487
if (!variables.empty())

src/GeneratorUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ IncludeGuardScope::IncludeGuardScope(
2121
return '_';
2222
}
2323

24-
return std::toupper(ch);
24+
return static_cast<char>(std::toupper(ch));
2525
});
2626

2727
_outputFile << R"cpp(// Copyright (c) Microsoft Corporation. All rights reserved.

src/GraphQLResponse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ Value::Value(const Value& other)
496496
std::transform(members.cbegin(),
497497
members.cend(),
498498
std::back_inserter(copy.members),
499-
[&copy](const auto& entry) noexcept {
499+
[](const auto& entry) noexcept {
500500
return entry.second;
501501
});
502502

0 commit comments

Comments
 (0)