Add compiler warnings override test. - #126
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new feature-verification regression test intended to ensure user-provided compiler flags (copts → user_compile_flags) take precedence over warning-related toolchain features by virtue of their ordering.
Changes:
- Added a new
cc_testtarget (warning_override_test) and included it in the rootfeature_verification_testssuite. - Added documentation describing the new test and updated expected test counts / listings.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/feature_verification/warning_override_test.cpp | New test source meant to validate warning-override flag ordering. |
| tests/feature_verification/BUILD | Adds the new cc_test target with copts + enabled warning feature(s). |
| tests/BUILD | Adds the new test to feature_verification_tests. |
| docs/test_suite.md | Documents the new test and updates expected counts/listing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Test for: warning feature override via user flags (copts) | ||
| // | ||
| // This test verifies that the ordering between warning features and user flags | ||
| // is correct. Specifically, it tests that: | ||
| // | ||
| // 1. A warning feature (e.g., strict_warnings) is enabled and emits -Wshadow | ||
| // 2. User provides -Wno-shadow via copts (which becomes user_compile_flags) | ||
| // 3. The compilation SUCCEEDS because user_compile_flags comes AFTER warning | ||
| // features in the features list, making user flags take precedence | ||
| // | ||
| // If the flag ordering regresses (e.g., warning features come after user flags), | ||
| // this test will fail to compile, catching the regression immediately. |
| // This function intentionally has variable shadowing, which triggers -Wshadow | ||
| // when strict_warnings or all_wall_warnings are enabled. The test provides | ||
| // -Wno-shadow via copts, so this should compile successfully if flag ordering | ||
| // is correct. | ||
| int shadow_function(int value) { | ||
| int result = value * 2; | ||
| { | ||
| // Intentional shadowing to trigger -Wshadow | ||
| int result = value * 3; | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| std::cout << "Warning override test: shadow_function(5) = " | ||
| << shadow_function(5) << std::endl; | ||
|
|
||
| std::cout << "Test passed! User -Wno-shadow flag successfully overrode " | ||
| << "the strict_warnings feature." << std::endl; | ||
|
|
||
| return 0; | ||
| } |
| 4. **`warning_override_test`** - Warning feature override via user flags | ||
| - Regression test verifying user flags (copts) can override enabled warning features | ||
| - Enables `strict_warnings` feature and provides conflicting `-Wno-shadow` via copts | ||
| - Validates that the flag ordering is correct: user_compile_flags comes after warning features, | ||
| ensuring user flags take precedence |
| # Test for: warning feature override via user_compile_flags | ||
| # Verifies that user-provided flags (via copts) can override enabled warning | ||
| # features. This regression test ensures that the flag ordering between warning | ||
| # features and user_compile_flags is correct: user_compile_flags must come | ||
| # after warning features so that user flags take precedence. | ||
| # | ||
| # The test enables strict_warnings (which emits -Wshadow) and provides | ||
| # -Wno-shadow via copts. If the flag ordering is correct, the test compiles | ||
| # successfully. If ordering regresses, compilation will fail with shadowing | ||
| # warnings, immediately catching the regression. | ||
| cc_test( | ||
| name = "warning_override_test", | ||
| srcs = ["warning_override_test.cpp"], | ||
| copts = ["-Wno-shadow"], | ||
| features = ["strict_warnings"], | ||
| ) |
| - Tests thread creation, synchronization, and joining | ||
| - Validates multiple threads can safely access shared state |
1848abb to
44fb302
Compare
Add compiler warnings override tests to verify feature warnings order.
44fb302 to
23f8c45
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (4)
tests/feature_verification/warning_override_test.cpp:23
- This test assumes
strict_warningsenables-Wshadow(and that-Wno-shadowcan override it), but the toolchain templates don’t add-Wshadowas part ofminimal_warnings/strict_warnings(e.g.templates/linux/cc_toolchain_flags.bzl.template:100-151). As written, the test is likely to compile regardless of flag ordering, so it won’t catch regressions.
// 1. strict_warnings (implies minimal_warnings which enables -Wall) and
// warnings_as_errors are both enabled, making -Wshadow an error
// 2. Code with variable shadowing would trigger an error
// 3. User provides -Wno-shadow via copts (which becomes user_compile_flags)
// 4. The compilation SUCCEEDS because user_compile_flags comes AFTER warning
tests/feature_verification/BUILD:156
- This test’s
copts/commentary are based on-Wshadow, but the toolchain warning features don’t currently enable-Wshadow, so the test may never exercise the intended failure mode. Consider switching to a warning that is actually enabled bystrict_warnings/-Wall(e.g. unused parameter) and overriding that instead.
# The test enables both strict_warnings and warnings_as_errors (making warnings
# into errors), then provides -Wno-shadow via copts. If the flag ordering is
# correct, the test compiles successfully because user's -Wno-shadow overrides
# the -Wshadow error. If ordering regresses, compilation will fail with a
# -Wshadow error, immediately catching the regression.
docs/test_suite.md:55
- The documentation describes this test as overriding
-Wshadowvia-Wno-shadow, but the toolchain warning features don’t currently enable-Wshadow, so that scenario is unlikely to be exercised. If the test is updated to override an actually-enabled warning (e.g.-Wunused-parametervia-Wno-unused-parameter), the docs should be updated to match.
- Regression test verifying user flags (copts) can override enabled warning features
- Enables both `strict_warnings` and `warnings_as_errors` features (making warnings into errors)
- Provides conflicting `-Wno-shadow` via copts to override the warning
- Validates that the flag ordering is correct: user_compile_flags comes after warning features,
ensuring user flags take precedence. If ordering regresses, compilation will fail with an error.
tests/feature_verification/warning_override_test.cpp:35
- The code currently triggers shadowing, but
-Wshadowis not enabled by the toolchain’s warning features, so this is unlikely to produce a warning/error even withwarnings_as_errors. Using a warning that is actually enabled by-Wall/-Wextra(e.g.-Wunused-parameter) will make this a reliable ordering regression test across toolchains.
// This function intentionally has variable shadowing, which triggers -Wshadow
// when strict_warnings or all_wall_warnings are enabled. The test provides
// -Wno-shadow via copts, so this should compile successfully if flag ordering
// is correct.
Add compiler warnings override tests to verify feature warnings order.