Skip to content

Commit a61bde1

Browse files
committed
Fix C4874 assignment-as-condition in Grapher.cpp - Refactored line 376 to extract assignment before condition check - Resolves C2220/C4874 build error - Fixes cascading build failures - Solution builds with 0 errors - Includes project retargeting to v145
1 parent ffd0519 commit a61bde1

13 files changed

Lines changed: 1042 additions & 43 deletions

File tree

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# C++ Build Tools Upgrade - Assessment Report
2+
3+
**Solution:** C:\Projects\oss\calculator\src\Calculator.sln
4+
**Platform Toolset:** v145
5+
**Windows SDK:** 10.0.26100.0
6+
**Date:** Generated during initial assessment
7+
**Total Issues:** 3 errors, 7 warnings across 6 projects
8+
9+
---
10+
11+
## Executive Summary
12+
13+
The solution has been retargeted to the latest Visual Studio build tools (v145), which has introduced new compiler warnings and exposed compatibility issues. The main issues are:
14+
15+
1. **Deprecated `/await` flag** - 5 projects use the deprecated `/await` flag for coroutine support
16+
2. **C4874 Warning treated as error** - New warning about assignment used as condition in Grapher.cpp
17+
3. **Cascading build failure** - GraphControl project fails to build, causing downstream projects to fail
18+
19+
---
20+
21+
## In-Scope Issues
22+
23+
These issues are directly related to the build tools upgrade and should be addressed:
24+
25+
### 1. Deprecated `/await` Compiler Flag (5 warnings)
26+
27+
**Warning Code:** D9047
28+
**Message:** "option 'await' has been deprecated and will be removed in a future release"
29+
30+
**Affected Projects:**
31+
- C:\Projects\oss\calculator\src\TraceLogging\TraceLogging.vcxproj (Build order: 1)
32+
- C:\Projects\oss\calculator\src\CalcManager\CalcManager.vcxproj (Build order: 3)
33+
- C:\Projects\oss\calculator\src\GraphControl\GraphControl.vcxproj (Build order: 6)
34+
- C:\Projects\oss\calculator\src\CalcViewModel\CalcViewModel.vcxproj (Build order: 7)
35+
- C:\Projects\oss\calculator\src\CalcViewModelCopyForUT\CalcViewModelCopyForUT.vcxproj (Build order: 8)
36+
- C:\Projects\oss\calculator\src\CalculatorUnitTests\CalculatorUnitTests.vcxproj (Build order: 9)
37+
38+
**Analysis:**
39+
- All projects are using `/std:c++17` with C++/CX (`/ZW` or `/ZW:nostdlib`)
40+
- The `/await` flag enables coroutine support for C++17, but is deprecated
41+
- Modern alternatives:
42+
- `/await:strict` - Standard-compliant coroutines (requires code changes to remove non-standard extensions)
43+
- Upgrade to C++20 with `/std:c++20` or newer (incompatible with `/ZW` C++/CX flag)
44+
45+
**Constraints:**
46+
- Solution uses C++/CX language extension (`/ZW` or `/ZW:nostdlib` flags present)
47+
- C++/CX is not compatible with C++20 or newer standards
48+
- Migration to C++20 would require removing C++/CX and refactoring to WinRT C++/WinRT
49+
- `/await:strict` requires refactoring code to remove non-standard extensions
50+
51+
---
52+
53+
### 2. C4874 Warning - Assignment Used as Condition (1 error, 1 warning)
54+
55+
**Error Code:** C2220
56+
**Message:** "the following warning is treated as an error"
57+
58+
**Warning Code:** C4874
59+
**Message:** "assignment used as a condition"
60+
61+
**Affected File:**
62+
- C:\Projects\oss\calculator\src\GraphControl\Control\Grapher.cpp (376, 33)
63+
64+
**Project:**
65+
- C:\Projects\oss\calculator\src\GraphControl\GraphControl.vcxproj (Build order: 6)
66+
67+
**Analysis:**
68+
The newer compiler has introduced a new warning C4874 that flags assignment expressions used as conditions. Since the project compiles with `/WX` (treat warnings as errors), this causes a build failure.
69+
70+
**Root Cause:**
71+
Line 376, column 33 in Grapher.cpp has code like: `if (x = y)` instead of `if (x == y)` or `if ((x = y))`
72+
73+
**Resolution Options:**
74+
1. Fix the code by enclosing assignment in parentheses: `if ((x = y))` - indicates intentional assignment
75+
2. Change to comparison if it's a bug: `if (x == y)`
76+
3. Temporarily use `/Wv:18` flag to revert to previous compiler warning behavior (not recommended)
77+
78+
**Impact:** This is a **blocking error** that prevents GraphControl.dll from building, causing cascading failures.
79+
80+
---
81+
82+
### 3. Cascading Build Failures (2 errors)
83+
84+
#### 3a. GraphControl WinMD Missing
85+
**Error Code:** C1192
86+
**Message:** "#using failed on 'C:\Projects\oss\calculator\src\x64\Debug\GraphControl\GraphControl.winmd'"
87+
88+
**Affected File:**
89+
- C:\Projects\oss\calculator\src\CalcViewModel\pch.cpp
90+
91+
**Project:**
92+
- C:\Projects\oss\calculator\src\CalcViewModel\CalcViewModel.vcxproj (Build order: 7)
93+
94+
**Analysis:**
95+
This error occurs because GraphControl.dll failed to build (due to C4874 error), so GraphControl.winmd was not generated. CalcViewModel depends on GraphControl and tries to reference the WinMD file in its precompiled header.
96+
97+
**Resolution:** Fix issue #2 (C4874 error) first, which will allow GraphControl to build successfully and generate the WinMD file.
98+
99+
---
100+
101+
#### 3b. CalcViewModelCopyForUT Library Missing
102+
**Error Code:** LNK1181
103+
**Message:** "cannot open input file 'C:\Projects\oss\calculator\src\x64\Debug\CalcViewModelCopyForUT\CalcViewModelCopyForUT.lib'"
104+
105+
**Project:**
106+
- C:\Projects\oss\calculator\src\CalculatorUnitTests\CalculatorUnitTests.vcxproj (Build order: 9)
107+
108+
**Analysis:**
109+
This is also a cascading error. CalcViewModelCopyForUT.lib was not built because:
110+
1. GraphControl failed to build (C4874 error)
111+
2. CalcViewModel failed to build (missing GraphControl.winmd)
112+
3. CalcViewModelCopyForUT likely depends on GraphControl and failed to build
113+
4. CalculatorUnitTests cannot link without CalcViewModelCopyForUT.lib
114+
115+
**Resolution:** Fix issue #2 (C4874 error) first, which should resolve the entire cascade.
116+
117+
---
118+
119+
## Out-of-Scope Issues
120+
121+
These issues are not related to the build tools upgrade:
122+
123+
*None identified* - All current errors and warnings are related to the build tools upgrade.
124+
125+
---
126+
127+
## Dependency Analysis
128+
129+
**Build Order & Dependencies:**
130+
1. TraceLogging (Build order 1) - Has deprecated `/await` warning
131+
2. CalcManager (Build order 3) - Has deprecated `/await` warning
132+
3. **GraphControl (Build order 6)** - **BLOCKED by C4874 error** - Has deprecated `/await` warning
133+
4. CalcViewModel (Build order 7) - Depends on GraphControl, blocked by cascading error
134+
5. CalcViewModelCopyForUT (Build order 8) - Depends on GraphControl, likely blocked
135+
6. CalculatorUnitTests (Build order 9) - Depends on CalcViewModelCopyForUT, blocked by cascading error
136+
137+
**Critical Path:**
138+
Fix GraphControl.cpp C4874 error → Unblocks CalcViewModel → Unblocks CalcViewModelCopyForUT → Unblocks CalculatorUnitTests
139+
140+
---
141+
142+
## Recommended Approach
143+
144+
### Priority 1: Unblock Build (Required)
145+
**Fix C4874 warning in Grapher.cpp** - This is the only blocking error preventing the entire solution from building.
146+
147+
### Priority 2: Address Deprecated `/await` Flag
148+
Since the solution uses C++/CX and C++17, we have limited options:
149+
150+
**Option A: Suppress the warning temporarily** (Least effort, temporary solution)
151+
- Keep `/await` and `/std:c++17`
152+
- Accept that the warning will remain until `/await` is removed by Microsoft
153+
- Minimal code changes
154+
155+
**Option B: Switch to `/await:strict`** (Moderate effort, better compatibility)
156+
- Replace `/await` with `/await:strict` in all affected projects
157+
- Requires code review to identify and fix non-standard coroutine extensions
158+
- Keeps C++17 and C++/CX compatibility
159+
- More future-proof than Option A
160+
161+
**Option C: Migrate to C++20 without C++/CX** (High effort, most modern)
162+
- Remove `/ZW` flags and migrate from C++/CX to C++/WinRT
163+
- Upgrade to `/std:c++20` or `/std:c++latest`
164+
- Remove `/await` flag (C++20 has native coroutine support)
165+
- Requires significant code refactoring across the entire solution
166+
- Most future-proof solution
167+
168+
---
169+
170+
## Impact Assessment
171+
172+
**Current State:**
173+
- ❌ Solution does NOT build
174+
- ❌ 3 errors block 4 projects
175+
- ⚠️ 7 warnings from deprecated flags
176+
177+
**After Priority 1 Fix (C4874):**
178+
- ✅ Solution builds successfully
179+
- ⚠️ 5-6 warnings remain from deprecated `/await` flag
180+
181+
**After Priority 2 Fix (Deprecated `/await`):**
182+
- ✅ Solution builds successfully
183+
- ✅ No build tools upgrade warnings
184+
185+
---
186+
187+
## Estimated Effort
188+
189+
| Priority | Issue | Effort | Risk |
190+
|----------|-------|--------|------|
191+
| P1 | Fix C4874 in Grapher.cpp | Low (1 line fix) | Low |
192+
| P2-A | Suppress `/await` warning | Low (update project settings) | Low (temporary) |
193+
| P2-B | Migrate to `/await:strict` | Medium (code review + fixes) | Medium |
194+
| P2-C | Migrate to C++20 + C++/WinRT | High (full refactor) | High |
195+
196+
---
197+
198+
## Next Steps
199+
200+
1. **Review this assessment** - Confirm the issues identified match expectations
201+
2. **Choose approach for deprecated `/await` flag** - Select Option A, B, or C based on:
202+
- Timeline and resources available
203+
- Long-term maintenance goals
204+
- Whether C++/CX to C++/WinRT migration is planned
205+
3. **Proceed to Planning Stage** - Generate detailed plan for chosen approach
206+
207+
---
208+
209+
## Questions for Decision Making
210+
211+
1. **Immediate Goal:** Do you want to just unblock the build (Priority 1 only), or address all warnings?
212+
2. **Long-term Strategy:** Is migrating away from C++/CX to C++/WinRT on the roadmap?
213+
3. **Timeline:** How much time is available for this upgrade?
214+
4. **Code Review:** Are there resources available to review coroutine usage if switching to `/await:strict`?
215+
216+
Please review this assessment and let me know which issues you would like me to address and which approach you prefer for the deprecated `/await` flag.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
## [2026-01-27 10:38] TASK-001: Verify prerequisites
3+
4+
Status: Complete
5+
6+
- **Verified**:
7+
- Visual Studio build tools v145 is installed and accessible (confirmed from assessment rebuild)
8+
- Windows SDK 10.0.26100.0 is installed (confirmed from assessment rebuild)
9+
- Solution C:\Projects\oss\calculator\src\Calculator.sln loads successfully
10+
- Current branch: main with pending changes (project retargeting)
11+
12+
Success - All prerequisites verified and ready for execution.
13+

0 commit comments

Comments
 (0)