[BUG] Make file_http_server.h compile on Windows#4300
Closed
thc1006 wants to merge 7 commits into
Closed
Conversation
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
Jul 24, 2026
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
14 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4300 +/- ##
==========================================
- Coverage 81.25% 81.24% -0.01%
==========================================
Files 446 446
Lines 18872 18872
==========================================
- Hits 15332 15330 -2
- Misses 3540 3542 +2 🚀 New features to boost your workflow:
|
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
Jul 25, 2026
Review of open-telemetry#4300 noted the fix had no regression protection: nothing in the repository includes this installed header, so every CI job could be green without the header ever being compiled, which is how the _WIN32 build error survived in the first place. Add a compile-only target (CMake OBJECT library and Bazel cc_library) whose sole translation unit includes the header. CI now compiles the POSIX branch on Linux and macOS and the _WIN32 branch on the Windows runners, so a future const-iterator std::replace, or any other build break in this header, fails immediately. Also add the direct <sstream> include the header needs for std::ostringstream; like the <algorithm> include, it was resolving only because socket_tools.h happens to provide it, and the new compile target is exactly what would surface that. Fixes open-telemetry#4299 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
FileGetSuccess() takes the path as a reference to const and then called std::replace over filename.begin() and filename.end(). Those are const iterators, so std::replace cannot write through them and the _WIN32 branch does not compile. This is a plain C++ error, not an MSVC quirk: clang 18 and gcc 12 both reject it when that branch is instantiated. It went unnoticed because no translation unit in the repository includes this header, so CI never compiles it on any platform, but it is an installed header and a downstream Windows build hits it immediately. The separator substitution now runs on a local copy, and <algorithm> is included directly rather than arriving by way of socket_tools.h. Fixes open-telemetry#4299 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Review of open-telemetry#4300 noted the fix had no regression protection: nothing in the repository includes this installed header, so every CI job could be green without the header ever being compiled, which is how the _WIN32 build error survived in the first place. Add a compile-only target (CMake OBJECT library and Bazel cc_library) whose sole translation unit includes the header. CI now compiles the POSIX branch on Linux and macOS and the _WIN32 branch on the Windows runners, so a future const-iterator std::replace, or any other build break in this header, fails immediately. Also add the direct <sstream> include the header needs for std::ostringstream; like the <algorithm> include, it was resolving only because socket_tools.h happens to provide it, and the new compile target is exactly what would surface that. Fixes open-telemetry#4299 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
The new header-compile translation unit is the first thing in the build to include file_http_server.h, so clang-tidy now lints it and counted two pre-existing warnings against the ratchet: find() and find_last_of() called with a single-character string literal. Pass the character directly so the header is lint-clean under the existing limit rather than raising it. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
The header-compile translation unit makes the maintainer -Wextra-semi -Werror configuration compile file_http_server.h for the first time, turning three pre-existing extra semicolons after in-class function bodies into errors. Drop them. The probe intentionally uses no symbol from the header, so mark its include IWYU pragma: keep. Also drop the unused <iostream> and guard <algorithm> behind _WIN32, where its only use (std::replace) lives. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
force-pushed
the
bugfix/file-http-server-windows-build
branch
from
July 25, 2026 08:26
aef50bf to
19749b6
Compare
Apply cmake-format with the repo config to the file_http_server_header_compile block.
…er-windows-build # Conflicts: # CHANGELOG.md
Member
|
This is dead code and will be removed in #4306 . Maybe this PR can be closed. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4299
Refs #4287
The problem
FileHttpServer::FileGetSuccess()calledstd::replace(filename.begin(), filename.end(), ...)on aconst std::string &, which yields const iterators, so the_WIN32branch could not compile. clang 18 and gcc 12 both reject it; it is plain C++, not an MSVC quirk. It survived because no translation unit in the repository includes this installed header, so CI never compiled it on any platform.The fix
The separator substitution runs on a local copy on Windows; the
#elsebranch binds a reference so other platforms do not pay for a copy.<sstream>is now included directly forstd::ostringstream, and<algorithm>(for the Windows-onlystd::replace) is included under_WIN32; both were previously resolving only becausesocket_tools.hhappens to include them.Regression protection (added in review)
The header still had no test compiling it, so the fix could regress unnoticed. A compile-only target (
file_http_server_header_compile, a CMake OBJECT library and a Bazelcc_library) now includes the header as its only translation unit. CI compiles the POSIX branch on Linux and macOS and the_WIN32branch on the Windows runners, so a compile-time break in the active platform branch of this header now fails the build. It is compiled, not run. It does not prove direct-include hygiene, since a symbol can still resolve through a transitive header; that is checked separately by the repository's IWYU workflow. The probe uses no symbol from the header on purpose, so its include is marked// IWYU pragma: keep.Compiling the header for the first time under the maintainer configuration also surfaced pre-existing issues in it that no build had seen before: three extra semicolons after in-class function bodies (errors under
-Wextra-semi -Werror) and two single-character string-literal searches,find(".")andfind_last_of("."), thatclang-tidy performance-faster-string-findflags. Both are fixed here so the header clears the same gates as the rest of the tree rather than raising a limit.Not in this PR
The header has neighbouring robustness gaps (unchecked
tellg(), ignoredread()result, non-ASCII filenames, URI query handling) and a path-confinement concern already being handled privately. They are recorded in #4287 rather than folded into this scoped build fix.Verification
-Wall -Wextra -Werror -Wextra-semion clang for C++14, 17 and 20, and on the repository's Windows runners for the_WIN32branch.main, keeping both the [BUG] Make file_http_server.h compile on Windows #4300 and [CODE HEALTH] Move SDK trace and metrics test helpers into anonymous namespaces #4303 CHANGELOG entries; GitHub reports the branch mergeable.