From f00c5aae9e31a77f437b076d738c3c07b50db1a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 07:25:31 +0000 Subject: [PATCH] Include in a generated semantic type [patch] A generated semantic type defaults `operator<=>`, which answers with one of the ordering types in . The header never included it. libstdc++ happens to have declared those types by the time the generated header is read and libc++ does not, so the type compiled under GCC and was refused by Clang: Kilograms.gen.hpp:35: error: cannot default 'operator<=>' because type 'std::partial_ordering' was not found; include Which is exactly the kind of difference a generator must not leave to whoever includes its output. Nothing about the schema says which standard library the target uses. It went unseen because every test that compiles generated C++ takes the first of `g++` or `clang++` on PATH, and on a Linux runner that is GCC. macOS returning to the test matrix in #188 is what surfaced it: there `g++` is a shim for AppleClang, and the whole suite compiles against libc++. The exemplar test pins the header byte for byte, so it now carries the include too - which is what keeps this checked on every platform rather than only on the one whose standard library is strict about it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01UGHDsYaaTQdzVR4XBR6miu --- Schema.Cpp.Test/ExemplarSemanticTypeTests.cs | 1 + Schema.Cpp/CppFileBuilder.cs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Schema.Cpp.Test/ExemplarSemanticTypeTests.cs b/Schema.Cpp.Test/ExemplarSemanticTypeTests.cs index 26a9bf9..d3c676e 100644 --- a/Schema.Cpp.Test/ExemplarSemanticTypeTests.cs +++ b/Schema.Cpp.Test/ExemplarSemanticTypeTests.cs @@ -55,6 +55,7 @@ public sealed class ExemplarSemanticTypeTests #pragma once + #include #include #include diff --git a/Schema.Cpp/CppFileBuilder.cs b/Schema.Cpp/CppFileBuilder.cs index f333f0d..6d74192 100644 --- a/Schema.Cpp/CppFileBuilder.cs +++ b/Schema.Cpp/CppFileBuilder.cs @@ -147,6 +147,13 @@ public SourceFile SemanticType(SchemaSemanticType semanticType) } declaration.Members.Add(Comparison(name, "==", "bool")); + + // A defaulted <=> answers with one of the ordering types, and those live in . + // libstdc++ happens to have declared them by the time this header is read and libc++ does + // not, so without this the generated type compiles under GCC and is refused by Clang - + // which is exactly the kind of difference a generator must not leave to whoever includes + // it. + mapper.Require(""); declaration.Members.Add(Comparison(name, "<=>", "auto")); declaration.Members.Add(new FieldDeclaration(ValueField, UnderlyingAlias) { Visibility = Visibility.Private });