Skip to content

Commit b996095

Browse files
authored
Merge pull request #41 from Microsoft/wravery
Applying some code analyzer suggestions
2 parents 7e3acf9 + a7f2b0b commit b996095

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

GraphQLService.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ std::string Base64::toBase64(const std::vector<uint8_t> & bytes)
517517
| static_cast<uint32_t>(data[2]);
518518

519519
result.append({
520-
verifyToBase64((segment & 0xFC0000) >> 18),
521-
verifyToBase64((segment & 0x3F000) >> 12),
522-
verifyToBase64((segment & 0xFC0) >> 6),
523-
verifyToBase64(segment & 0x3F)
520+
verifyToBase64(static_cast<uint8_t>((segment & 0xFC0000) >> 18)),
521+
verifyToBase64(static_cast<uint8_t>((segment & 0x3F000) >> 12)),
522+
verifyToBase64(static_cast<uint8_t>((segment & 0xFC0) >> 6)),
523+
verifyToBase64(static_cast<uint8_t>(segment & 0x3F))
524524
});
525525

526526
data += 3;
@@ -534,9 +534,9 @@ std::string Base64::toBase64(const std::vector<uint8_t> & bytes)
534534
const uint16_t segment = (static_cast<uint16_t>(data[0]) << 8)
535535
| (pair ? static_cast<uint16_t>(data[1]) : 0);
536536
const std::array<char, 4> remainder {
537-
verifyToBase64((segment & 0xFC00) >> 10),
538-
verifyToBase64((segment & 0x3F0) >> 4),
539-
(pair ? verifyToBase64((segment & 0xF) << 2) : padding),
537+
verifyToBase64(static_cast<uint8_t>((segment & 0xFC00) >> 10)),
538+
verifyToBase64(static_cast<uint8_t>((segment & 0x3F0) >> 4)),
539+
(pair ? verifyToBase64(static_cast<uint8_t>((segment & 0xF) << 2)) : padding),
540540
padding
541541
};
542542

@@ -1098,11 +1098,11 @@ bool Object::matchesType(const std::string & typeName) const
10981098
return _typeNames.find(typeName) != _typeNames.cend();
10991099
}
11001100

1101-
void Object::beginSelectionSet(const SelectionSetParams & params) const
1101+
void Object::beginSelectionSet(const SelectionSetParams &) const
11021102
{
11031103
}
11041104

1105-
void Object::endSelectionSet(const SelectionSetParams & params) const
1105+
void Object::endSelectionSet(const SelectionSetParams &) const
11061106
{
11071107
}
11081108

@@ -1157,7 +1157,7 @@ class OperationDefinitionVisitor
11571157

11581158
std::future<response::Value> getValue();
11591159

1160-
void visit(std::string operationType, const peg::ast_node& operationDefinition);
1160+
void visit(const std::string& operationType, const peg::ast_node& operationDefinition);
11611161

11621162
private:
11631163
std::shared_ptr<OperationData> _params;
@@ -1182,7 +1182,7 @@ std::future<response::Value> OperationDefinitionVisitor::getValue()
11821182
return result;
11831183
}
11841184

1185-
void OperationDefinitionVisitor::visit(std::string operationType, const peg::ast_node & operationDefinition)
1185+
void OperationDefinitionVisitor::visit(const std::string & operationType, const peg::ast_node & operationDefinition)
11861186
{
11871187
auto itr = _operations.find(operationType);
11881188

Introspection.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void Schema::AddSubscriptionType(std::shared_ptr<ObjectType> subscription)
2626
_subscription = std::move(subscription);
2727
}
2828

29-
void Schema::AddType(response::StringType name, std::shared_ptr<object::__Type> type)
29+
void Schema::AddType(response::StringType&& name, std::shared_ptr<object::__Type> type)
3030
{
3131
_typeMap[name] = _types.size();
3232
_types.push_back({ std::move(name), std::move(type) });
@@ -112,7 +112,7 @@ std::future<std::vector<std::shared_ptr<object::__Directive>>> Schema::getDirect
112112
return promise.get_future();
113113
}
114114

115-
BaseType::BaseType(response::StringType description)
115+
BaseType::BaseType(response::StringType&& description)
116116
: _description(std::move(description))
117117
{
118118
}
@@ -191,7 +191,7 @@ std::future<std::shared_ptr<object::__Type>> BaseType::getOfType(service::FieldP
191191
return promise.get_future();
192192
}
193193

194-
ScalarType::ScalarType(response::StringType name, response::StringType description)
194+
ScalarType::ScalarType(response::StringType&& name, response::StringType&& description)
195195
: BaseType(std::move(description))
196196
, _name(std::move(name))
197197
{
@@ -215,7 +215,7 @@ std::future<std::unique_ptr<response::StringType>> ScalarType::getName(service::
215215
return promise.get_future();
216216
}
217217

218-
ObjectType::ObjectType(response::StringType name, response::StringType description)
218+
ObjectType::ObjectType(response::StringType&& name, response::StringType&& description)
219219
: BaseType(std::move(description))
220220
, _name(std::move(name))
221221
{
@@ -278,7 +278,7 @@ std::future<std::unique_ptr<std::vector<std::shared_ptr<object::__Type>>>> Objec
278278
return promise.get_future();
279279
}
280280

281-
InterfaceType::InterfaceType(response::StringType name, response::StringType description)
281+
InterfaceType::InterfaceType(response::StringType&& name, response::StringType&& description)
282282
: BaseType(std::move(description))
283283
, _name(std::move(name))
284284
{
@@ -325,7 +325,7 @@ std::future<std::unique_ptr<std::vector<std::shared_ptr<object::__Field>>>> Inte
325325
return promise.get_future();
326326
}
327327

328-
UnionType::UnionType(response::StringType name, response::StringType description)
328+
UnionType::UnionType(response::StringType&& name, response::StringType&& description)
329329
: BaseType(std::move(description))
330330
, _name(std::move(name))
331331
{
@@ -369,7 +369,7 @@ std::future<std::unique_ptr<std::vector<std::shared_ptr<object::__Type>>>> Union
369369
return promise.get_future();
370370
}
371371

372-
EnumType::EnumType(response::StringType name, response::StringType description)
372+
EnumType::EnumType(response::StringType&& name, response::StringType&& description)
373373
: BaseType(std::move(description))
374374
, _name(std::move(name))
375375
{
@@ -425,7 +425,7 @@ std::future<std::unique_ptr<std::vector<std::shared_ptr<object::__EnumValue>>>>
425425
return promise.get_future();
426426
}
427427

428-
InputObjectType::InputObjectType(response::StringType name, response::StringType description)
428+
InputObjectType::InputObjectType(response::StringType&& name, response::StringType&& description)
429429
: BaseType(std::move(description))
430430
, _name(std::move(name))
431431
{
@@ -490,7 +490,7 @@ std::future<std::shared_ptr<object::__Type>> WrapperType::getOfType(service::Fie
490490
return promise.get_future();
491491
}
492492

493-
Field::Field(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, const std::shared_ptr<object::__Type>& type)
493+
Field::Field(response::StringType&& name, response::StringType&& description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>>&& args, const std::shared_ptr<object::__Type>& type)
494494
: _name(std::move(name))
495495
, _description(std::move(description))
496496
, _deprecationReason(std::move(deprecationReason))
@@ -559,7 +559,7 @@ std::future<std::unique_ptr<response::StringType>> Field::getDeprecationReason(s
559559
return promise.get_future();
560560
}
561561

562-
InputValue::InputValue(response::StringType name, response::StringType description, const std::shared_ptr<object::__Type>& type, response::StringType defaultValue)
562+
InputValue::InputValue(response::StringType&& name, response::StringType&& description, const std::shared_ptr<object::__Type>& type, response::StringType&& defaultValue)
563563
: _name(std::move(name))
564564
, _description(std::move(description))
565565
, _type(type)
@@ -607,7 +607,7 @@ std::future<std::unique_ptr<response::StringType>> InputValue::getDefaultValue(s
607607
return promise.get_future();
608608
}
609609

610-
EnumValue::EnumValue(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason)
610+
EnumValue::EnumValue(response::StringType&& name, response::StringType&& description, std::unique_ptr<response::StringType>&& deprecationReason)
611611
: _name(std::move(name))
612612
, _description(std::move(description))
613613
, _deprecationReason(std::move(deprecationReason))
@@ -654,7 +654,7 @@ std::future<std::unique_ptr<response::StringType>> EnumValue::getDeprecationReas
654654
return promise.get_future();
655655
}
656656

657-
Directive::Directive(response::StringType name, response::StringType description, std::vector<response::StringType> locations, std::vector<std::shared_ptr<InputValue>> args)
657+
Directive::Directive(response::StringType&& name, response::StringType&& description, std::vector<response::StringType>&& locations, std::vector<std::shared_ptr<InputValue>>&& args)
658658
: _name(std::move(name))
659659
, _description(std::move(description))
660660
, _locations([](std::vector<response::StringType>&& locationsArg) -> std::vector<__DirectiveLocation>

SchemaGenerator.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Generator::Generator()
151151
}
152152
}
153153

154-
Generator::Generator(std::string schemaFileName, std::string filenamePrefix, std::string schemaNamespace)
154+
Generator::Generator(std::string&& schemaFileName, std::string&& filenamePrefix, std::string&& schemaNamespace)
155155
: _isIntrospection(false)
156156
, _filenamePrefix(std::move(filenamePrefix))
157157
, _schemaNamespace(std::move(schemaNamespace))
@@ -1531,7 +1531,7 @@ std::string Generator::getFieldDeclaration(const OutputField & outputField, bool
15311531
std::ostringstream output;
15321532
std::string fieldName(outputField.name);
15331533

1534-
fieldName[0] = std::toupper(fieldName[0]);
1534+
fieldName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(fieldName[0])));
15351535
output << R"cpp( virtual std::future<)cpp" << getOutputCppType(outputField, interfaceField)
15361536
<< R"cpp(> get)cpp" << fieldName << R"cpp((service::FieldParams&& params)cpp";
15371537

@@ -1552,7 +1552,7 @@ std::string Generator::getResolverDeclaration(const OutputField & outputField) c
15521552
std::ostringstream output;
15531553
std::string fieldName(outputField.name);
15541554

1555-
fieldName[0] = std::toupper(fieldName[0]);
1555+
fieldName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(fieldName[0])));
15561556
output << R"cpp( std::future<response::Value> resolve)cpp" << fieldName
15571557
<< R"cpp((service::ResolverParams&& params);
15581558
)cpp";
@@ -1747,7 +1747,7 @@ template <>
17471747
}
17481748

17491749
firstField = false;
1750-
fieldName[0] = std::toupper(fieldName[0]);
1750+
fieldName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(fieldName[0])));
17511751
sourceFile << R"cpp( std::move(value)cpp" << fieldName << R"cpp())cpp";
17521752
}
17531753

@@ -1819,7 +1819,7 @@ namespace object {
18191819

18201820
std::string fieldName(outputField.name);
18211821

1822-
fieldName[0] = std::toupper(fieldName[0]);
1822+
fieldName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(fieldName[0])));
18231823
sourceFile << R"cpp( { ")cpp" << outputField.name
18241824
<< R"cpp(", [this](service::ResolverParams&& params) { return resolve)cpp" << fieldName
18251825
<< R"cpp((std::move(params)); } })cpp";
@@ -1873,7 +1873,7 @@ namespace object {
18731873
{
18741874
std::string fieldName(outputField.name);
18751875

1876-
fieldName[0] = std::toupper(fieldName[0]);
1876+
fieldName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(fieldName[0])));
18771877
sourceFile << R"cpp(
18781878
std::future<response::Value> )cpp" << objectType.type
18791879
<< R"cpp(::resolve)cpp" << fieldName
@@ -1931,7 +1931,7 @@ std::future<response::Value> )cpp" << objectType.type
19311931
{
19321932
std::string argumentName(argument.name);
19331933

1934-
argumentName[0] = std::toupper(argumentName[0]);
1934+
argumentName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(argumentName[0])));
19351935
sourceFile << R"cpp(, std::move(arg)cpp" << argumentName << R"cpp())cpp";
19361936
}
19371937
}
@@ -2541,7 +2541,7 @@ Operations::Operations()cpp";
25412541
{
25422542
std::string operation(operationType.operation);
25432543

2544-
operation[0] = std::toupper(operation[0]);
2544+
operation[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(operation[0])));
25452545
sourceFile << R"cpp( schema->Add)cpp" << operation
25462546
<< R"cpp(Type(type)cpp" << operationType.type
25472547
<< R"cpp();
@@ -2689,7 +2689,7 @@ std::string Generator::getArgumentDeclaration(const InputField & argument, const
26892689
std::ostringstream argumentDeclaration;
26902690
std::string argumentName(argument.name);
26912691

2692-
argumentName[0] = std::toupper(argumentName[0]);
2692+
argumentName[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(argumentName[0])));
26932693
if (argument.defaultValue.type() == response::Type::Null)
26942694
{
26952695
argumentDeclaration << R"cpp( auto )cpp" << prefixToken << argumentName

include/SchemaGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class Generator
200200
explicit Generator();
201201

202202
// Initialize the generator with the GraphQL schema and output parameters.
203-
explicit Generator(std::string schemaFileName, std::string filenamePrefix, std::string schemaNamespace);
203+
explicit Generator(std::string&& schemaFileName, std::string&& filenamePrefix, std::string&& schemaNamespace);
204204

205205
// Run the generator and return a list of filenames that were output.
206206
std::vector<std::string> Build() const noexcept;

include/graphqlservice/GraphQLService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ struct OperationData : std::enable_shared_from_this<OperationData>
630630
// SelectionSet against the payload.
631631
using SubscriptionCallback = std::function<void(std::future<response::Value>)>;
632632
using SubscriptionArguments = std::unordered_map<std::string, response::Value>;
633-
using SubscriptionFilterCallback = std::function<bool(response::MapType::const_reference) noexcept>;
633+
using SubscriptionFilterCallback = std::function<bool(response::MapType::const_reference)>;
634634

635635
// Subscriptions are stored in maps using these keys.
636636
using SubscriptionKey = size_t;

include/graphqlservice/Introspection.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Schema : public object::__Schema
3030
void AddQueryType(std::shared_ptr<ObjectType> query);
3131
void AddMutationType(std::shared_ptr<ObjectType> mutation);
3232
void AddSubscriptionType(std::shared_ptr<ObjectType> subscription);
33-
void AddType(response::StringType name, std::shared_ptr<object::__Type> type);
33+
void AddType(response::StringType&& name, std::shared_ptr<object::__Type> type);
3434
const std::shared_ptr<object::__Type>& LookupType(const response::StringType& name) const;
3535
const std::shared_ptr<object::__Type>& WrapType(__TypeKind kind, const std::shared_ptr<object::__Type>& ofType);
3636
void AddDirective(std::shared_ptr<object::__Directive> directive);
@@ -67,7 +67,7 @@ class BaseType : public object::__Type
6767
std::future<std::shared_ptr<object::__Type>> getOfType(service::FieldParams&& params) const override;
6868

6969
protected:
70-
BaseType(response::StringType description);
70+
BaseType(response::StringType&& description);
7171

7272
private:
7373
const response::StringType _description;
@@ -76,7 +76,7 @@ class BaseType : public object::__Type
7676
class ScalarType : public BaseType
7777
{
7878
public:
79-
explicit ScalarType(response::StringType name, response::StringType description);
79+
explicit ScalarType(response::StringType&& name, response::StringType&& description);
8080

8181
// Accessors
8282
std::future<__TypeKind> getKind(service::FieldParams&& params) const override;
@@ -89,7 +89,7 @@ class ScalarType : public BaseType
8989
class ObjectType : public BaseType
9090
{
9191
public:
92-
explicit ObjectType(response::StringType name, response::StringType description);
92+
explicit ObjectType(response::StringType&& name, response::StringType&& description);
9393

9494
void AddInterfaces(std::vector<std::shared_ptr<InterfaceType>> interfaces);
9595
void AddFields(std::vector<std::shared_ptr<Field>> fields);
@@ -110,7 +110,7 @@ class ObjectType : public BaseType
110110
class InterfaceType : public BaseType
111111
{
112112
public:
113-
explicit InterfaceType(response::StringType name, response::StringType description);
113+
explicit InterfaceType(response::StringType&& name, response::StringType&& description);
114114

115115
void AddFields(std::vector<std::shared_ptr<Field>> fields);
116116

@@ -128,7 +128,7 @@ class InterfaceType : public BaseType
128128
class UnionType : public BaseType
129129
{
130130
public:
131-
explicit UnionType(response::StringType name, response::StringType description);
131+
explicit UnionType(response::StringType&& name, response::StringType&& description);
132132

133133
void AddPossibleTypes(std::vector<std::weak_ptr<object::__Type>> possibleTypes);
134134

@@ -153,7 +153,7 @@ struct EnumValueType
153153
class EnumType : public BaseType
154154
{
155155
public:
156-
explicit EnumType(response::StringType name, response::StringType description);
156+
explicit EnumType(response::StringType&& name, response::StringType&& description);
157157

158158
void AddEnumValues(std::vector<EnumValueType> enumValues);
159159

@@ -171,7 +171,7 @@ class EnumType : public BaseType
171171
class InputObjectType : public BaseType
172172
{
173173
public:
174-
explicit InputObjectType(response::StringType name, response::StringType description);
174+
explicit InputObjectType(response::StringType&& name, response::StringType&& description);
175175

176176
void AddInputValues(std::vector<std::shared_ptr<InputValue>> inputValues);
177177

@@ -203,7 +203,7 @@ class WrapperType : public BaseType
203203
class Field : public object::__Field
204204
{
205205
public:
206-
explicit Field(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, const std::shared_ptr<object::__Type>& type);
206+
explicit Field(response::StringType&& name, response::StringType&& description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>>&& args, const std::shared_ptr<object::__Type>& type);
207207

208208
// Accessors
209209
std::future<response::StringType> getName(service::FieldParams&& params) const override;
@@ -224,7 +224,7 @@ class Field : public object::__Field
224224
class InputValue : public object::__InputValue
225225
{
226226
public:
227-
explicit InputValue(response::StringType name, response::StringType description, const std::shared_ptr<object::__Type>& type, response::StringType defaultValue);
227+
explicit InputValue(response::StringType&& name, response::StringType&& description, const std::shared_ptr<object::__Type>& type, response::StringType&& defaultValue);
228228

229229
// Accessors
230230
std::future<response::StringType> getName(service::FieldParams&& params) const override;
@@ -242,7 +242,7 @@ class InputValue : public object::__InputValue
242242
class EnumValue : public object::__EnumValue
243243
{
244244
public:
245-
explicit EnumValue(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason);
245+
explicit EnumValue(response::StringType&& name, response::StringType&& description, std::unique_ptr<response::StringType>&& deprecationReason);
246246

247247
// Accessors
248248
std::future<response::StringType> getName(service::FieldParams&& params) const override;
@@ -259,7 +259,7 @@ class EnumValue : public object::__EnumValue
259259
class Directive : public object::__Directive
260260
{
261261
public:
262-
explicit Directive(response::StringType name, response::StringType description, std::vector<response::StringType> locations, std::vector<std::shared_ptr<InputValue>> args);
262+
explicit Directive(response::StringType&& name, response::StringType&& description, std::vector<response::StringType>&& locations, std::vector<std::shared_ptr<InputValue>>&& args);
263263

264264
// Accessors
265265
std::future<response::StringType> getName(service::FieldParams&& params) const override;

0 commit comments

Comments
 (0)