Make public headers safe for consumers building with -Werror - #1501
Merged
bmehta001 merged 4 commits intoJul 9, 2026
Conversation
Consumers that embed the SDK and compile with -Wall -Wextra -Werror (e.g. ONNX Runtime / Foundry Local via add_subdirectory) were broken by warnings emitted from inside the SDK's public headers. Two complementary changes fix this: Primary (covers every consumer + every warning flag): mark mat's exported public include directory as SYSTEM. find_package consumers already treat an imported target's includes as system; SYSTEM extends that to add_subdirectory/FetchContent consumers, so their -Werror no longer promotes SDK-header warnings to errors. Verified: an -isystem consumer compiles clean under -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror on gcc and clang. Defense in depth (also helps non-CMake consumers and NO_SYSTEM_FROM_IMPORTED): - UNREFERENCED_PARAMETER(...) expanded to nothing on gcc/clang, leaving the parameter unused; it now casts to void, eliminating 5 -Wunused-parameter warnings across NullObjects.hpp and LogManagerProvider.hpp. - assert(!"msg") triggered -Wstring-conversion on clang; switched to the canonical assert(false && "msg") in ISemanticContext.hpp (2 sites). Result: including the main public headers under -Wall -Wextra now yields 0 warnings (was 5). SDK's own top-level build verified unaffected (75 UNREFERENCED_PARAMETER call sites compile clean). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure the SDK’s public headers can be included by downstream consumers that build with strict warning-as-error flags (e.g. -Wall -Wextra -Werror), especially when consuming via add_subdirectory/FetchContent.
Changes:
- Mark
mat’s exported public include directory as a SYSTEM include inlib/CMakeLists.txtto suppress warnings originating from SDK public headers in consumer builds. - Fix
UNREFERENCED_PARAMETER(...)inctmacros.hppto reliably reference unused parameters on non-Windows compilers. - Replace
assert(!"message")withassert(false && "message")inISemanticContext.hppto avoid clang diagnostics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/include/public/ISemanticContext.hpp | Adjusts assertion idiom in enum-to-string switches to avoid clang warnings. |
| lib/include/public/ctmacros.hpp | Makes UNREFERENCED_PARAMETER actually reference parameters under gcc/clang to prevent -Wunused-parameter. |
| lib/CMakeLists.txt | Marks public include dir as SYSTEM for consumer builds (currently also impacts private includes in same call). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review comment on lib/CMakeLists.txt:358. The SYSTEM keyword is a per-call flag, so a single target_include_directories(mat SYSTEM PUBLIC ... PRIVATE ...) also marked the SDK-internal PRIVATE include dirs as system for mat's own build, which would suppress warnings in the SDK's own internal headers under -Werror. Split into two calls: SYSTEM PUBLIC for the exported public dir, and a separate non-SYSTEM PRIVATE call for internal dirs. Verified via CMake property query: INTERFACE_SYSTEM_INCLUDE_DIRECTORIES contains only the public dir; the private internal dirs return to their original (non-system) treatment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Is it possible to align the build flags used in this repo's pipelines with those that ort expects so we don't see errors when integrating with ort in the future? |
baijumeswani
approved these changes
Jul 9, 2026
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.
Summary
Consumers that embed this SDK and compile their own code with
-Wall -Wextra -Werror(e.g. ONNX Runtime / Foundry Local, which consume the SDK viaadd_subdirectory) were broken by warnings emitted from inside the SDK's public headers. This PR makes the public headers safe to include under strict, warning-as-error builds.Two complementary changes:
1. Mark the exported public include dir as
SYSTEM(primary fix)lib/CMakeLists.txtnow usestarget_include_directories(mat SYSTEM PUBLIC ...).find_packageconsumers already treat an imported target's includes as system headers (so their warnings are suppressed); theSYSTEMkeyword extends the same courtesy toadd_subdirectory/FetchContentconsumers. This covers every consumer and every warning flag — including diagnostics that have no clean C++11 header-level fix (-Wpedanticvariadic-macro warnings from theLM_SAFE_CALLfamily,-Wsign-conversionin theVariantunion).2. Header hygiene (defense in depth)
Also fixes the actual warnings, which helps non-CMake consumers (Bazel/Buck/Make copying the headers) and CMake consumers that set
NO_SYSTEM_FROM_IMPORTED:ctmacros.hpp—UNREFERENCED_PARAMETER(...)expanded to nothing on gcc/clang (there was aTODOacknowledging this), so the parameter stayed unused and tripped-Wunused-parameter. It now casts the argument tovoid, eliminating 5-Wunused-parameterwarnings acrossNullObjects.hppandLogManagerProvider.hpp.ISemanticContext.hpp— theassert(!"message")idiom triggers clang's-Wstring-conversion; switched to the canonicalassert(false && "message")(2 sites).Impact on a consumer including the main public headers
-Wall -Wextra+ -Wpedantic+ -Wshadow -Wconversion(clang)Validation
LogManager.hpp,EventProperties.hpp,CorrelationVector.hpp,PayloadDecoder.hpp,Variant.hpp,LogManagerProvider.hpp):-Wall -Wextradrops 5 → 0.add_subdirectoryand confirmedmat'sINTERFACE_SYSTEM_INCLUDE_DIRECTORIEScontains the public include dir.-isystemcompiles clean under-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werroron both gcc and clang; and a minimaladd_subdirectoryreproduction confirmed a consumer's-Werrorfails withoutSYSTEMand passes with it.libmat.so) compiles cleanly with theUNREFERENCED_PARAMETERchange across all 75 call sites.Public API and ABI are unchanged (
UNREFERENCED_PARAMETERis a no-side-effect discard; theassertchange is textual). The default build is otherwise unaffected.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com