Skip to content

Commit 44fb302

Browse files
committed
Add compiler warnings override test.
Add compiler warnings override tests to verify feature warnings order.
1 parent fb3c265 commit 44fb302

4 files changed

Lines changed: 88 additions & 13 deletions

File tree

‎docs/test_suite.md‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,54 @@ These tests verify that specific toolchain features are correctly implemented an
4747
- Tests strict_warnings, minimal_warnings, warnings_as_errors features
4848
- Includes code patterns that trigger specific warnings
4949

50-
4. **`coverage_test`** - Code coverage instrumentation
50+
4. **`warning_override_test`** - Warning feature override via user flags
51+
- Regression test verifying user flags (copts) can override enabled warning features
52+
- Enables `strict_warnings` feature and provides conflicting `-Wno-shadow` via copts
53+
- Validates that the flag ordering is correct: user_compile_flags comes after warning features,
54+
ensuring user flags take precedence
55+
56+
5. **`coverage_test`** - Code coverage instrumentation
5157
- Verifies code coverage instrumentation flags are applied
5258
- Provides multiple code paths for coverage analysis
5359
- Can be analyzed with: `bazel coverage --combined_report=lcov //feature_verification:coverage_test`
5460

55-
5. **`pic_test`** - Position-Independent Code (`-fPIC`)
61+
6. **`pic_test`** - Position-Independent Code (`-fPIC`)
5662
- Tests -fPIC flag is correctly applied
5763
- Validates position-independent code patterns
5864
- Tests polymorphism, static variables, and C linkage with PIC
5965

60-
6. **`pthread_test`** - POSIX threading support
66+
7. **`pthread_test`** - POSIX threading support
6167
- Verifies `-lpthread` correctly links pthread library
6268
- Tests thread creation, synchronization, and joining
6369
- Validates multiple threads can safely access shared state
6470

65-
7. **`multifile_test`** - Multi-file compilation and archiving
71+
8. **`multifile_test`** - Multi-file compilation and archiving
6672
- Tests multiple source files compile into separate object files
6773
- Validates object files are combined by archiver into static libraries
6874
- Complex operations across multiple object files link correctly
6975

70-
8. **`whole_archive_test`** - Whole-archive linking (`-Wl,--whole-archive`)
76+
9. **`whole_archive_test`** - Whole-archive linking (`-Wl,--whole-archive`)
7177
- Verifies `-Wl,--whole-archive` and `-Wl,--no-whole-archive` work
7278
- Tests unused library symbols are linked when using whole-archive
7379

74-
9. **`preprocessor_defines_test`** - `preprocessor_defines` feature
80+
10. **`preprocessor_defines_test`** - `preprocessor_defines` feature
7581
- Injects defines via the `local_defines` attribute (routed through the
7682
`preprocessor_defines` feature), unlike `defines_test` which uses `copts`
7783
(routed through `user_compile_flags`)
7884

79-
10. **`include_dir_test`** - `include_paths` via the `includes` attribute
85+
11. **`include_dir_test`** - `include_paths` via the `includes` attribute
8086
- Includes a header exposed through a library's `includes` attribute,
8187
exercising the `-I`/`-isystem` search paths
8288

83-
11. **`user_link_flags_test`** - `user_link_flags` feature
89+
12. **`user_link_flags_test`** - `user_link_flags` feature
8490
- Passes a linker flag through `linkopts` (`-Wl,--defsym=...`) and checks the
8591
injected symbol's address at runtime
8692

87-
12. **`random_seed_test`** - `random_seed` feature
93+
13. **`random_seed_test`** - `random_seed` feature
8894
- Build-and-run smoke test exercising internal-linkage symbols governed by
8995
the reproducible-build random seed
9096

91-
13. **`fully_static_link_test`** - `fully_static_link` feature (`-static`)
97+
14. **`fully_static_link_test`** - `fully_static_link` feature (`-static`)
9298
- Verifies no shared objects are mapped at runtime (fully static binary)
9399
- Marked incompatible with toolchains lacking static system archives (AutoSD)
94100

@@ -279,16 +285,16 @@ when the host equals the target).
279285

280286
### All tests on the host (`//...`)
281287
```
282-
Executed 13 tests: 13 passed
288+
Executed 20 tests: 20 passed
283289
```
284290

285291
### Feature Verification Tests
286-
- The `feature_verification_tests` suite aggregates 7 tests. `warnings_test`
292+
- The `feature_verification_tests` suite aggregates 13 tests. `warnings_test`
287293
is defined separately and is picked up by wildcard targets such as
288294
`//feature_verification/...`.
289295
- Expected output for the suite:
290296
```
291-
Executed 7 tests: 7 passed
297+
Executed 13 tests: 13 passed
292298
```
293299

294300
### Language and Standards Tests
@@ -318,6 +324,7 @@ tests/
318324
│ ├── random_seed_test.cpp
319325
│ ├── fully_static_link_test.cpp
320326
│ ├── warnings_test.cpp
327+
│ ├── warning_override_test.cpp
321328
│ ├── coverage_test.cpp
322329
│ ├── pic_test_lib.h/cpp, pic_test.cpp
323330
│ ├── multifile_lib.h and multifile_lib_*.cpp

‎tests/BUILD‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ test_suite(
4949
"//feature_verification:pthread_test",
5050
"//feature_verification:random_seed_test",
5151
"//feature_verification:user_link_flags_test",
52+
"//feature_verification:warning_override_test",
5253
"//feature_verification:whole_archive_test",
5354
],
5455
)

‎tests/feature_verification/BUILD‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ cc_test(
143143
srcs = ["warnings_test.cpp"],
144144
)
145145

146+
# Test for: warning feature override via user_compile_flags
147+
# Verifies that user-provided flags (via copts) can override enabled warning
148+
# features. This regression test ensures that the flag ordering between warning
149+
# features and user_compile_flags is correct: user_compile_flags must come
150+
# after warning features so that user flags take precedence.
151+
#
152+
# The test enables strict_warnings (which emits -Wshadow) and provides
153+
# -Wno-shadow via copts. If the flag ordering is correct, the test compiles
154+
# successfully. If ordering regresses, compilation will fail with shadowing
155+
# warnings, immediately catching the regression.
156+
cc_test(
157+
name = "warning_override_test",
158+
srcs = ["warning_override_test.cpp"],
159+
copts = ["-Wno-shadow"],
160+
features = ["strict_warnings"],
161+
)
162+
146163
# Test for: coverage, gcc_coverage_map_format, dependency_file features
147164
# Verifies that code coverage instrumentation is applied. Also used by both
148165
# Linux and QNX CI as the `bazel coverage` smoke test (build/link/execute/gcov
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/********************************************************************************
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Apache License Version 2.0 which is available at
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* SPDX-License-Identifier: Apache-2.0
12+
********************************************************************************/
13+
14+
// Test for: warning feature override via user flags (copts)
15+
//
16+
// This test verifies that the ordering between warning features and user flags
17+
// is correct. Specifically, it tests that:
18+
//
19+
// 1. A warning feature (e.g., strict_warnings) is enabled and emits -Wshadow
20+
// 2. User provides -Wno-shadow via copts (which becomes user_compile_flags)
21+
// 3. The compilation SUCCEEDS because user_compile_flags comes AFTER warning
22+
// features in the features list, making user flags take precedence
23+
//
24+
// If the flag ordering regresses (e.g., warning features come after user flags),
25+
// this test will fail to compile, catching the regression immediately.
26+
27+
#include <iostream>
28+
29+
// This function intentionally has variable shadowing, which triggers -Wshadow
30+
// when strict_warnings or all_wall_warnings are enabled. The test provides
31+
// -Wno-shadow via copts, so this should compile successfully if flag ordering
32+
// is correct.
33+
int shadow_function(int value) {
34+
int result = value * 2;
35+
{
36+
// Intentional shadowing to trigger -Wshadow
37+
int result = value * 3;
38+
return result;
39+
}
40+
}
41+
42+
int main() {
43+
std::cout << "Warning override test: shadow_function(5) = "
44+
<< shadow_function(5) << std::endl;
45+
46+
std::cout << "Test passed! User -Wno-shadow flag successfully overrode "
47+
<< "the strict_warnings feature." << std::endl;
48+
49+
return 0;
50+
}

0 commit comments

Comments
 (0)