Docs: AGENTS.template.md says standard headers are never #included, and five library units and twelve tests include C and POSIX headers #207

Open
opened 2026-11-27 08:01:33 +00:00 by jorijnvdgraaf · 1 comment

Summary

The guide's code style says "import std; everywhere. Standard headers are never #included; [...] Tests may #include <cstdlib>, <cstring> or <cstddef> for the macros import std; does not provide." (AGENTS.template.md:97 at 148ed01). The code does otherwise, in files older than #167's fix as well: C and POSIX headers are included wherever a unit needs errno, stdout, mmap, poll, a socket or a child process, which import std; does not provide.

Details

At 148ed01:

  • Library units, each in its global module fragment: interfaces/Crafter.Graphics-Window.cppm (<stdio.h>, <stdlib.h>, <unistd.h>, <string.h>, <sys/mman.h>, <errno.h>, <fcntl.h>); implementations/Crafter.Graphics-Window.cpp (the same, and <sys/stat.h>, <time.h>, <poll.h>); implementations/Crafter.Graphics-Device.cpp (<string.h>, <stdio.h>, <stdlib.h>, <errno.h>, <unistd.h>, <sys/mman.h>); implementations/Crafter.Graphics-Clipboard.cpp (<unistd.h>, <errno.h>, <poll.h>, <fcntl.h>); implementations/Crafter.Graphics-Gamepad.cpp (<fcntl.h>, <unistd.h>, <poll.h>, <sys/ioctl.h>).
  • Tests with C, C++ or POSIX headers besides those three: ConfigureResize, TextInputContent, TitleWayland and ToplevelState (<sys/socket.h>, <unistd.h>, <cerrno>); DebugMessengerSeverity (<cstdio>, <unistd.h>); DeviceSelection (<sys/wait.h>, <unistd.h>); HeapASRead and HeapDynamicIndexHit (<cstdio>); KeyboardKeymap (<cerrno>, <cstdio>, <fcntl.h>, <sys/mman.h>, <sys/wait.h>, <unistd.h>, <malloc.h>); ResizeViewport (<fcntl.h>, <unistd.h>, <cstdio>); VulkanBufferResizeReuse (<cstdint>); WindowUpdateClock (<cstdio>, <sys/eventfd.h>, <unistd.h>).

Found in the pre-push review of #167's fix, whose <errno.h> in Device.cpp and the headers of its new test are among these.

Suggested fix

Write down the rule the code keeps: C++ standard headers are never included (import std;); C and POSIX headers go in the global module fragment, behind the backend's #ifdef, where a unit needs a macro or a system call that import std; does not provide (errno, stdout, mmap, poll); tests include them as they need them.

## Summary The guide's code style says "`import std;` everywhere. Standard headers are never `#include`d; [...] Tests may `#include <cstdlib>`, `<cstring>` or `<cstddef>` for the macros `import std;` does not provide." (`AGENTS.template.md:97` at `148ed01`). The code does otherwise, in files older than #167's fix as well: C and POSIX headers are included wherever a unit needs `errno`, `stdout`, `mmap`, `poll`, a socket or a child process, which `import std;` does not provide. ## Details At `148ed01`: - Library units, each in its global module fragment: `interfaces/Crafter.Graphics-Window.cppm` (`<stdio.h>`, `<stdlib.h>`, `<unistd.h>`, `<string.h>`, `<sys/mman.h>`, `<errno.h>`, `<fcntl.h>`); `implementations/Crafter.Graphics-Window.cpp` (the same, and `<sys/stat.h>`, `<time.h>`, `<poll.h>`); `implementations/Crafter.Graphics-Device.cpp` (`<string.h>`, `<stdio.h>`, `<stdlib.h>`, `<errno.h>`, `<unistd.h>`, `<sys/mman.h>`); `implementations/Crafter.Graphics-Clipboard.cpp` (`<unistd.h>`, `<errno.h>`, `<poll.h>`, `<fcntl.h>`); `implementations/Crafter.Graphics-Gamepad.cpp` (`<fcntl.h>`, `<unistd.h>`, `<poll.h>`, `<sys/ioctl.h>`). - Tests with C, C++ or POSIX headers besides those three: ConfigureResize, TextInputContent, TitleWayland and ToplevelState (`<sys/socket.h>`, `<unistd.h>`, `<cerrno>`); DebugMessengerSeverity (`<cstdio>`, `<unistd.h>`); DeviceSelection (`<sys/wait.h>`, `<unistd.h>`); HeapASRead and HeapDynamicIndexHit (`<cstdio>`); KeyboardKeymap (`<cerrno>`, `<cstdio>`, `<fcntl.h>`, `<sys/mman.h>`, `<sys/wait.h>`, `<unistd.h>`, `<malloc.h>`); ResizeViewport (`<fcntl.h>`, `<unistd.h>`, `<cstdio>`); VulkanBufferResizeReuse (`<cstdint>`); WindowUpdateClock (`<cstdio>`, `<sys/eventfd.h>`, `<unistd.h>`). Found in the pre-push review of #167's fix, whose `<errno.h>` in `Device.cpp` and the headers of its new test are among these. ## Suggested fix Write down the rule the code keeps: C++ standard headers are never included (`import std;`); C and POSIX headers go in the global module fragment, behind the backend's `#ifdef`, where a unit needs a macro or a system call that `import std;` does not provide (`errno`, `stdout`, `mmap`, `poll`); tests include them as they need them.
Author
Owner

e1ca2fd (#169) adds two tests to the list: WindowConstructorThrow (<cstdio>, <dlfcn.h>, <fcntl.h>, <unistd.h>) and WindowConstructorThrowWin32 (<cstdio>, for the stdout its Check flushes).

`e1ca2fd` (#169) adds two tests to the list: WindowConstructorThrow (`<cstdio>`, `<dlfcn.h>`, `<fcntl.h>`, `<unistd.h>`) and WindowConstructorThrowWin32 (`<cstdio>`, for the `stdout` its `Check` flushes).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Graphics#207
No description provided.