Skip to content

Make public headers safe for consumers building with -Werror - #1501

Merged
bmehta001 merged 4 commits into
microsoft:mainfrom
bmehta001:bhamehta/consumer-werror-clean
Jul 9, 2026
Merged

Make public headers safe for consumers building with -Werror#1501
bmehta001 merged 4 commits into
microsoft:mainfrom
bmehta001:bhamehta/consumer-werror-clean

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

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 via add_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.txt now uses target_include_directories(mat SYSTEM PUBLIC ...). find_package consumers already treat an imported target's includes as system headers (so their warnings are suppressed); the SYSTEM keyword extends the same courtesy to add_subdirectory/FetchContent consumers. This covers every consumer and every warning flag — including diagnostics that have no clean C++11 header-level fix (-Wpedantic variadic-macro warnings from the LM_SAFE_CALL family, -Wsign-conversion in the Variant union).

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.hppUNREFERENCED_PARAMETER(...) expanded to nothing on gcc/clang (there was a TODO acknowledging this), so the parameter stayed unused and tripped -Wunused-parameter. It now casts the argument to void, eliminating 5 -Wunused-parameter warnings across NullObjects.hpp and LogManagerProvider.hpp.
  • ISemanticContext.hpp — the assert(!"message") idiom triggers clang's -Wstring-conversion; switched to the canonical assert(false && "message") (2 sites).

Impact on a consumer including the main public headers

Consumer flags Before After (headers only) After (with SYSTEM)
-Wall -Wextra 5 0 0
+ -Wpedantic 22 17 0
+ -Wshadow -Wconversion (clang) 9 2 0

Validation

  • Header re-measure (gcc 13 + clang 18, including LogManager.hpp, EventProperties.hpp, CorrelationVector.hpp, PayloadDecoder.hpp, Variant.hpp, LogManagerProvider.hpp): -Wall -Wextra drops 5 → 0.
  • SYSTEM propagation: configured the SDK via add_subdirectory and confirmed mat's INTERFACE_SYSTEM_INCLUDE_DIRECTORIES contains the public include dir.
  • End-to-end: a consumer treating the public dir as -isystem compiles clean under -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror on both gcc and clang; and a minimal add_subdirectory reproduction confirmed a consumer's -Werror fails without SYSTEM and passes with it.
  • No SDK regression: the SDK's own top-level legacy build (libmat.so) compiles cleanly with the UNREFERENCED_PARAMETER change across all 75 call sites.

Public API and ABI are unchanged (UNREFERENCED_PARAMETER is a no-side-effect discard; the assert change is textual). The default build is otherwise unaffected.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

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>
@bmehta001
bmehta001 requested a review from a team as a code owner July 7, 2026 23:40
@bmehta001
bmehta001 requested a review from Copilot July 7, 2026 23:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in lib/CMakeLists.txt to suppress warnings originating from SDK public headers in consumer builds.
  • Fix UNREFERENCED_PARAMETER(...) in ctmacros.hpp to reliably reference unused parameters on non-Windows compilers.
  • Replace assert(!"message") with assert(false && "message") in ISemanticContext.hpp to 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.

Comment thread lib/CMakeLists.txt Outdated
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@baijumeswani

Copy link
Copy Markdown
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?

@bmehta001 bmehta001 self-assigned this Jul 9, 2026
@bmehta001
bmehta001 merged commit fa2734c into microsoft:main Jul 9, 2026
31 of 34 checks passed
@bmehta001
bmehta001 deleted the bhamehta/consumer-werror-clean branch July 9, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants