From ec7802686caa2a89cad5463241a80c7385145816 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Fri, 6 Sep 2024 17:35:44 -0700 Subject: [PATCH 1/3] fix: client input type member default init error on clang 14 --- .../client/multiple/MultipleQueriesClient.cpp | 4 ++++ .../client/multiple/MultipleQueriesClient.h | 8 +++---- samples/client/mutate/MutateClient.cpp | 4 ++++ samples/client/mutate/MutateClient.h | 8 +++---- .../client/nestedinput/NestedInputClient.cpp | 9 ++++++++ .../client/nestedinput/NestedInputClient.h | 18 +++++++-------- src/ClientGenerator.cpp | 22 ++++++++++++++----- 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/samples/client/multiple/MultipleQueriesClient.cpp b/samples/client/multiple/MultipleQueriesClient.cpp index 3f56012f..ed6de3e3 100644 --- a/samples/client/multiple/MultipleQueriesClient.cpp +++ b/samples/client/multiple/MultipleQueriesClient.cpp @@ -122,6 +122,10 @@ const peg::ast& GetRequestObject() noexcept } CompleteTaskInput::CompleteTaskInput() noexcept + : id {} + , testTaskState {} + , isComplete {} + , clientMutationId {} { // Explicit definition to prevent ODR violations when LTO is enabled. } diff --git a/samples/client/multiple/MultipleQueriesClient.h b/samples/client/multiple/MultipleQueriesClient.h index 4e27c2d2..af157461 100644 --- a/samples/client/multiple/MultipleQueriesClient.h +++ b/samples/client/multiple/MultipleQueriesClient.h @@ -140,10 +140,10 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput CompleteTaskInput& operator=(const CompleteTaskInput& other); CompleteTaskInput& operator=(CompleteTaskInput&& other) noexcept; - response::IdType id {}; - std::optional testTaskState {}; - std::optional isComplete {}; - std::optional clientMutationId {}; + response::IdType id; + std::optional testTaskState; + std::optional isComplete; + std::optional clientMutationId; }; } // namespace multiple diff --git a/samples/client/mutate/MutateClient.cpp b/samples/client/mutate/MutateClient.cpp index 06b030e5..027a03c9 100644 --- a/samples/client/mutate/MutateClient.cpp +++ b/samples/client/mutate/MutateClient.cpp @@ -55,6 +55,10 @@ const peg::ast& GetRequestObject() noexcept } CompleteTaskInput::CompleteTaskInput() noexcept + : id {} + , testTaskState {} + , isComplete {} + , clientMutationId {} { // Explicit definition to prevent ODR violations when LTO is enabled. } diff --git a/samples/client/mutate/MutateClient.h b/samples/client/mutate/MutateClient.h index ff918f35..a2f304eb 100644 --- a/samples/client/mutate/MutateClient.h +++ b/samples/client/mutate/MutateClient.h @@ -73,10 +73,10 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput CompleteTaskInput& operator=(const CompleteTaskInput& other); CompleteTaskInput& operator=(CompleteTaskInput&& other) noexcept; - response::IdType id {}; - std::optional testTaskState {}; - std::optional isComplete {}; - std::optional clientMutationId {}; + response::IdType id; + std::optional testTaskState; + std::optional isComplete; + std::optional clientMutationId; }; } // namespace mutate diff --git a/samples/client/nestedinput/NestedInputClient.cpp b/samples/client/nestedinput/NestedInputClient.cpp index 33f2fa80..2832d921 100644 --- a/samples/client/nestedinput/NestedInputClient.cpp +++ b/samples/client/nestedinput/NestedInputClient.cpp @@ -49,6 +49,7 @@ const peg::ast& GetRequestObject() noexcept } InputA::InputA() noexcept + : a {} { // Explicit definition to prevent ODR violations when LTO is enabled. } @@ -87,6 +88,7 @@ InputA& InputA::operator=(InputA&& other) noexcept } InputB::InputB() noexcept + : b {} { // Explicit definition to prevent ODR violations when LTO is enabled. } @@ -125,6 +127,11 @@ InputB& InputB::operator=(InputB&& other) noexcept } InputABCD::InputABCD() noexcept + : d {} + , a {} + , b {} + , bc {} + , value {} { // Explicit definition to prevent ODR violations when LTO is enabled. } @@ -183,6 +190,8 @@ InputABCD& InputABCD::operator=(InputABCD&& other) noexcept } InputBC::InputBC() noexcept + : c {} + , b {} { // Explicit definition to prevent ODR violations when LTO is enabled. } diff --git a/samples/client/nestedinput/NestedInputClient.h b/samples/client/nestedinput/NestedInputClient.h index 83984da7..78eefa17 100644 --- a/samples/client/nestedinput/NestedInputClient.h +++ b/samples/client/nestedinput/NestedInputClient.h @@ -56,7 +56,7 @@ struct [[nodiscard("unnecessary construction")]] InputA InputA& operator=(const InputA& other); InputA& operator=(InputA&& other) noexcept; - bool a {}; + bool a; }; struct [[nodiscard("unnecessary construction")]] InputB @@ -71,7 +71,7 @@ struct [[nodiscard("unnecessary construction")]] InputB InputB& operator=(const InputB& other); InputB& operator=(InputB&& other) noexcept; - double b {}; + double b; }; struct InputBC; @@ -92,11 +92,11 @@ struct [[nodiscard("unnecessary construction")]] InputABCD InputABCD& operator=(const InputABCD& other); InputABCD& operator=(InputABCD&& other) noexcept; - std::string d {}; - InputA a {}; - InputB b {}; - std::vector bc {}; - int value {}; + std::string d; + InputA a; + InputB b; + std::vector bc; + int value; }; struct [[nodiscard("unnecessary construction")]] InputBC @@ -112,8 +112,8 @@ struct [[nodiscard("unnecessary construction")]] InputBC InputBC& operator=(const InputBC& other); InputBC& operator=(InputBC&& other) noexcept; - response::IdType c {}; - InputB b {}; + response::IdType c; + InputB b; }; } // namespace nestedinput diff --git a/src/ClientGenerator.cpp b/src/ClientGenerator.cpp index 0f36d0be..1a747ec5 100644 --- a/src/ClientGenerator.cpp +++ b/src/ClientGenerator.cpp @@ -319,7 +319,7 @@ static_assert(graphql::internal::MinorVersion == )cpp" headerFile << R"cpp( )cpp" << _requestLoader.getInputCppType(inputField->type().lock()) << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) - << R"cpp( {}; + << R"cpp(; )cpp"; } @@ -648,7 +648,20 @@ using namespace std::literals; pendingSeparator.reset(); - sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept + sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept)cpp"; + + bool firstField = true; + + for (const auto& inputField : inputType.type->inputFields()) + { + sourceFile << R"cpp( + )cpp" << (firstField ? R"cpp(:)cpp" : R"cpp(,)cpp") + << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) + << R"cpp( {})cpp"; + firstField = false; + } + + sourceFile << R"cpp( { // Explicit definition to prevent ODR violations when LTO is enabled. } @@ -656,7 +669,7 @@ using namespace std::literals; )cpp" << cppType << R"cpp(::)cpp" << cppType << R"cpp(()cpp"; - bool firstField = true; + firstField = true; for (const auto& inputField : inputType.type->inputFields()) { @@ -854,8 +867,7 @@ response::Value Variable<)cpp" sourceFile << R"cpp(template <> response::Value Variable<)cpp" - << cppType << R"cpp(>::serialize()cpp" << cppType - << R"cpp(&& inputValue) + << cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& inputValue) { response::Value result { response::Type::Map }; From 6fd05b966fd2aae35ee3761a9cb9d5fdb93c5bd7 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Fri, 6 Sep 2024 17:39:37 -0700 Subject: [PATCH 2/3] fix: #304 --- include/graphqlservice/internal/Grammar.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/graphqlservice/internal/Grammar.h b/include/graphqlservice/internal/Grammar.h index df0bf46a..8f3824b1 100644 --- a/include/graphqlservice/internal/Grammar.h +++ b/include/graphqlservice/internal/Grammar.h @@ -65,7 +65,7 @@ struct comment : seq, until> }; // https://spec.graphql.org/October2021/#sec-Source-Text.Ignored-Tokens -struct ignored : sor, comment> +struct ignored : sor, comment> { }; @@ -1177,7 +1177,7 @@ struct mixed_definition : sor, star, // leading whitespace/ignored + : seq, // leading whitespace/ignored list>, // mixed definitions star, tao::graphqlpeg::eof> // trailing whitespace/ignored { @@ -1189,7 +1189,7 @@ struct mixed_document : must }; struct executable_document_content - : seq, star, // leading whitespace/ignored + : seq, // leading whitespace/ignored list>, // executable definitions star, tao::graphqlpeg::eof> // trailing whitespace/ignored { @@ -1206,7 +1206,7 @@ struct schema_type_definition : sor, star, // leading whitespace/ignored + : seq, // leading whitespace/ignored list>, // schema type definitions star, tao::graphqlpeg::eof> // trailing whitespace/ignored { From b07ebd4ebd1012e861a255e610c0e0619a21370a Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Fri, 6 Sep 2024 17:50:25 -0700 Subject: [PATCH 3/3] chore(test): update unit tests for latest bug fixes --- test/PegtlExecutableTests.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/PegtlExecutableTests.cpp b/test/PegtlExecutableTests.cpp index 3a010f73..4dc47120 100644 --- a/test/PegtlExecutableTests.cpp +++ b/test/PegtlExecutableTests.cpp @@ -233,10 +233,25 @@ TEST(PegtlExecutableCase, ParserDepthLimitExceeded) TEST(PegtlExecutableCase, ParseFloatWithFractionalAndExponentialParts) { - memory_input<> input(R"gql({ field(value: 1.1e1) })gql", + memory_input<> input(R"gql( + query { + combinedField(value: 1.1e1) + onlyFractional(value: 1.1) + onlyExponent(value: 1e1) + })gql", "ParseFloatWithFractionalAndExponentialParts"); const bool result = parse(input); + ASSERT_TRUE(result) << "we should be able to parse the doc"; +} + +TEST(PegtlExecutableCase, ParseIgnoreUnicodeBOM) +{ + memory_input<> input("query { \xEF\xBB\xBF __typename }", + "ParseIgnoreUnicodeBOM"); + + const bool result = parse(input); + ASSERT_TRUE(result) << "we should be able to parse the doc"; } \ No newline at end of file