Skip to content

Commit 49a4d58

Browse files
authored
Merge pull request #308 from wravery/fix-304
2 parents f671c66 + b07ebd4 commit 49a4d58

File tree

9 files changed

+71
-27
lines changed

9 files changed

+71
-27
lines changed

include/graphqlservice/internal/Grammar.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct comment : seq<one<'#'>, until<eolf>>
6565
};
6666

6767
// https://spec.graphql.org/October2021/#sec-Source-Text.Ignored-Tokens
68-
struct ignored : sor<space, one<','>, comment>
68+
struct ignored : sor<utf8::bom, space, one<','>, comment>
6969
{
7070
};
7171

@@ -1177,7 +1177,7 @@ struct mixed_definition : sor<executable_definition, type_system_definition, typ
11771177
};
11781178

11791179
struct mixed_document_content
1180-
: seq<bof, opt<utf8::bom>, star<ignored>, // leading whitespace/ignored
1180+
: seq<bof, star<ignored>, // leading whitespace/ignored
11811181
list<mixed_definition, star<ignored>>, // mixed definitions
11821182
star<ignored>, tao::graphqlpeg::eof> // trailing whitespace/ignored
11831183
{
@@ -1189,7 +1189,7 @@ struct mixed_document : must<mixed_document_content>
11891189
};
11901190

11911191
struct executable_document_content
1192-
: seq<bof, opt<utf8::bom>, star<ignored>, // leading whitespace/ignored
1192+
: seq<bof, star<ignored>, // leading whitespace/ignored
11931193
list<executable_definition, star<ignored>>, // executable definitions
11941194
star<ignored>, tao::graphqlpeg::eof> // trailing whitespace/ignored
11951195
{
@@ -1206,7 +1206,7 @@ struct schema_type_definition : sor<type_system_definition, type_system_extensio
12061206
};
12071207

12081208
struct schema_document_content
1209-
: seq<bof, opt<utf8::bom>, star<ignored>, // leading whitespace/ignored
1209+
: seq<bof, star<ignored>, // leading whitespace/ignored
12101210
list<schema_type_definition, star<ignored>>, // schema type definitions
12111211
star<ignored>, tao::graphqlpeg::eof> // trailing whitespace/ignored
12121212
{

samples/client/multiple/MultipleQueriesClient.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ const peg::ast& GetRequestObject() noexcept
122122
}
123123

124124
CompleteTaskInput::CompleteTaskInput() noexcept
125+
: id {}
126+
, testTaskState {}
127+
, isComplete {}
128+
, clientMutationId {}
125129
{
126130
// Explicit definition to prevent ODR violations when LTO is enabled.
127131
}

samples/client/multiple/MultipleQueriesClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
140140
CompleteTaskInput& operator=(const CompleteTaskInput& other);
141141
CompleteTaskInput& operator=(CompleteTaskInput&& other) noexcept;
142142

143-
response::IdType id {};
144-
std::optional<TaskState> testTaskState {};
145-
std::optional<bool> isComplete {};
146-
std::optional<std::string> clientMutationId {};
143+
response::IdType id;
144+
std::optional<TaskState> testTaskState;
145+
std::optional<bool> isComplete;
146+
std::optional<std::string> clientMutationId;
147147
};
148148

149149
} // namespace multiple

samples/client/mutate/MutateClient.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ const peg::ast& GetRequestObject() noexcept
5555
}
5656

5757
CompleteTaskInput::CompleteTaskInput() noexcept
58+
: id {}
59+
, testTaskState {}
60+
, isComplete {}
61+
, clientMutationId {}
5862
{
5963
// Explicit definition to prevent ODR violations when LTO is enabled.
6064
}

samples/client/mutate/MutateClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
7373
CompleteTaskInput& operator=(const CompleteTaskInput& other);
7474
CompleteTaskInput& operator=(CompleteTaskInput&& other) noexcept;
7575

76-
response::IdType id {};
77-
std::optional<TaskState> testTaskState {};
78-
std::optional<bool> isComplete {};
79-
std::optional<std::string> clientMutationId {};
76+
response::IdType id;
77+
std::optional<TaskState> testTaskState;
78+
std::optional<bool> isComplete;
79+
std::optional<std::string> clientMutationId;
8080
};
8181

8282
} // namespace mutate

samples/client/nestedinput/NestedInputClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const peg::ast& GetRequestObject() noexcept
4949
}
5050

5151
InputA::InputA() noexcept
52+
: a {}
5253
{
5354
// Explicit definition to prevent ODR violations when LTO is enabled.
5455
}
@@ -87,6 +88,7 @@ InputA& InputA::operator=(InputA&& other) noexcept
8788
}
8889

8990
InputB::InputB() noexcept
91+
: b {}
9092
{
9193
// Explicit definition to prevent ODR violations when LTO is enabled.
9294
}
@@ -125,6 +127,11 @@ InputB& InputB::operator=(InputB&& other) noexcept
125127
}
126128

127129
InputABCD::InputABCD() noexcept
130+
: d {}
131+
, a {}
132+
, b {}
133+
, bc {}
134+
, value {}
128135
{
129136
// Explicit definition to prevent ODR violations when LTO is enabled.
130137
}
@@ -183,6 +190,8 @@ InputABCD& InputABCD::operator=(InputABCD&& other) noexcept
183190
}
184191

185192
InputBC::InputBC() noexcept
193+
: c {}
194+
, b {}
186195
{
187196
// Explicit definition to prevent ODR violations when LTO is enabled.
188197
}

samples/client/nestedinput/NestedInputClient.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct [[nodiscard("unnecessary construction")]] InputA
5656
InputA& operator=(const InputA& other);
5757
InputA& operator=(InputA&& other) noexcept;
5858

59-
bool a {};
59+
bool a;
6060
};
6161

6262
struct [[nodiscard("unnecessary construction")]] InputB
@@ -71,7 +71,7 @@ struct [[nodiscard("unnecessary construction")]] InputB
7171
InputB& operator=(const InputB& other);
7272
InputB& operator=(InputB&& other) noexcept;
7373

74-
double b {};
74+
double b;
7575
};
7676

7777
struct InputBC;
@@ -92,11 +92,11 @@ struct [[nodiscard("unnecessary construction")]] InputABCD
9292
InputABCD& operator=(const InputABCD& other);
9393
InputABCD& operator=(InputABCD&& other) noexcept;
9494

95-
std::string d {};
96-
InputA a {};
97-
InputB b {};
98-
std::vector<InputBC> bc {};
99-
int value {};
95+
std::string d;
96+
InputA a;
97+
InputB b;
98+
std::vector<InputBC> bc;
99+
int value;
100100
};
101101

102102
struct [[nodiscard("unnecessary construction")]] InputBC
@@ -112,8 +112,8 @@ struct [[nodiscard("unnecessary construction")]] InputBC
112112
InputBC& operator=(const InputBC& other);
113113
InputBC& operator=(InputBC&& other) noexcept;
114114

115-
response::IdType c {};
116-
InputB b {};
115+
response::IdType c;
116+
InputB b;
117117
};
118118

119119
} // namespace nestedinput

src/ClientGenerator.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
319319
headerFile << R"cpp( )cpp"
320320
<< _requestLoader.getInputCppType(inputField->type().lock())
321321
<< R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name())
322-
<< R"cpp( {};
322+
<< R"cpp(;
323323
)cpp";
324324
}
325325

@@ -648,15 +648,28 @@ using namespace std::literals;
648648

649649
pendingSeparator.reset();
650650

651-
sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept
651+
sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept)cpp";
652+
653+
bool firstField = true;
654+
655+
for (const auto& inputField : inputType.type->inputFields())
656+
{
657+
sourceFile << R"cpp(
658+
)cpp" << (firstField ? R"cpp(:)cpp" : R"cpp(,)cpp")
659+
<< R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name())
660+
<< R"cpp( {})cpp";
661+
firstField = false;
662+
}
663+
664+
sourceFile << R"cpp(
652665
{
653666
// Explicit definition to prevent ODR violations when LTO is enabled.
654667
}
655668
656669
)cpp" << cppType << R"cpp(::)cpp"
657670
<< cppType << R"cpp(()cpp";
658671

659-
bool firstField = true;
672+
firstField = true;
660673

661674
for (const auto& inputField : inputType.type->inputFields())
662675
{
@@ -854,8 +867,7 @@ response::Value Variable<)cpp"
854867

855868
sourceFile << R"cpp(template <>
856869
response::Value Variable<)cpp"
857-
<< cppType << R"cpp(>::serialize()cpp" << cppType
858-
<< R"cpp(&& inputValue)
870+
<< cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& inputValue)
859871
{
860872
response::Value result { response::Type::Map };
861873

test/PegtlExecutableTests.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,25 @@ TEST(PegtlExecutableCase, ParserDepthLimitExceeded)
233233

234234
TEST(PegtlExecutableCase, ParseFloatWithFractionalAndExponentialParts)
235235
{
236-
memory_input<> input(R"gql({ field(value: 1.1e1) })gql",
236+
memory_input<> input(R"gql(
237+
query {
238+
combinedField(value: 1.1e1)
239+
onlyFractional(value: 1.1)
240+
onlyExponent(value: 1e1)
241+
})gql",
237242
"ParseFloatWithFractionalAndExponentialParts");
238243

239244
const bool result = parse<executable_document>(input);
240245

246+
ASSERT_TRUE(result) << "we should be able to parse the doc";
247+
}
248+
249+
TEST(PegtlExecutableCase, ParseIgnoreUnicodeBOM)
250+
{
251+
memory_input<> input("query { \xEF\xBB\xBF __typename }",
252+
"ParseIgnoreUnicodeBOM");
253+
254+
const bool result = parse<executable_document>(input);
255+
241256
ASSERT_TRUE(result) << "we should be able to parse the doc";
242257
}

0 commit comments

Comments
 (0)