Skip to content

Conversation

@dmachaj
Copy link
Contributor

@dmachaj dmachaj commented Apr 24, 2025

Fixes: #1486

Why is this change being made?

The most recent PR introduced a warning for non-Clang consumers. Many projects build with warnings-as-errors so this is a build break for those projects. Because cppwinrt is widely used by many such projects it should itself build with warnings as errors enabled so that this doesn't happen again in the future. Plus it is general goodness to build with warnings cranked up and blocking.

Briefly summarize what changed

I added /WX to every single vcxproj in this repo (which required a whole lot of redundant edits). Many of them didn't have /W4 so I added it wherever it was missing. The project files definitely need some refactoring to reduce duplication. But for this change I decided to modify them as-is without also including a refactoring.

I also fixed the newly-blocking warnings. Fortunately the project was basically clean and only the recent issue needed fixing.

I also removed a typo'd (warning is singular, not plural) that was trying to disable warnings in one specific project. It has no warnings so we might as well baseline them as blocking.

How was this change tested?

It builds locally (x64 Debug+Release, only tested MSVC).

Copy link

Copilot AI left a comment

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 updates the cppwinrt project files to enable /W4 and /WX for stricter warning enforcement and fixes the resulting issues. The changes primarily adjust attribute detection checks in header files to ensure compatibility on Clang and resolve a typo in a project file.

  • Updated preprocessor conditions in header files to check for __has_attribute before using it.
  • Ensured consistency in attribute detection across files.

Reviewed Changes

Copilot reviewed 29 out of 47 changed files in this pull request and generated no comments.

File Description
strings/base_macros.h Revised attribute check logic with nested __has_attribute validation.
strings/base_fast_forward.h Similar update to attribute detection with added guard for __has_attribute.
Files not reviewed (18)
  • Directory.Build.Props: Language not supported
  • cppwinrt/cppwinrt.vcxproj: Language not supported
  • natvis/cppwinrtvisualizer.vcxproj: Language not supported
  • prebuild/prebuild.vcxproj: Language not supported
  • scratch/scratch.vcxproj: Language not supported
  • test/nuget/ConsoleApplication1/ConsoleApplication1.vcxproj: Language not supported
  • test/nuget/TestApp/TestApp.vcxproj: Language not supported
  • test/nuget/TestProxyStub/TestProxyStub.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponent1/TestRuntimeComponent1.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponent2/TestRuntimeComponent2.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponent3/TestRuntimeComponent3.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponentCX/TestRuntimeComponentCX.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponentCXReferencingWinRTStaticLibrary/TestRuntimeComponentCXReferencingWinRTStaticLibrary.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponentEmpty/TestRuntimeComponentEmpty.vcxproj: Language not supported
  • test/nuget/TestRuntimeComponentNamespaceUnderscore/TestRuntimeComponentNamespaceUnderscore.vcxproj: Language not supported
  • test/nuget/TestStaticLibrary1/TestStaticLibrary1.vcxproj: Language not supported
  • test/nuget/TestStaticLibrary2/TestStaticLibrary2.vcxproj: Language not supported
  • test/nuget/TestStaticLibrary3/TestStaticLibrary3.vcxproj: Language not supported

@dmachaj
Copy link
Contributor Author

dmachaj commented Apr 24, 2025

3>Class.cpp(522,10): error : unused function 'ValidateStaticEventAutoRevoke' [-Werror,-Wunused-function] [D:\a\cppwinrt\cppwinrt\test\test_component\test_component.vcxproj]

I guess I need to figure out how to build with clang-cl.exe. Last time I tried I wasn't able to get it working locally.

dunhor
dunhor previously approved these changes Apr 24, 2025
@dunhor
Copy link
Member

dunhor commented Apr 24, 2025

3>Class.cpp(522,10): error : unused function 'ValidateStaticEventAutoRevoke' [-Werror,-Wunused-function] [D:\a\cppwinrt\cppwinrt\test\test_component\test_component.vcxproj]

I guess I need to figure out how to build with clang-cl.exe. Last time I tried I wasn't able to get it working locally.

Probably because the function is defined in an anonymous namespace. Could just try moving it to the global namespace

@dmachaj
Copy link
Contributor Author

dmachaj commented Apr 24, 2025

I was able to figure out how to get enough of clang-cl to build to reproduce the break:

msbuild /m /clp:ForceConsoleColor /p:Configuration=Debug,Platform=x64,CppWinRTBuildVersion=1.2.3.4,Clang=1,PlatformToolset=ClangCl cppwinrt.sln /t:fast_fwd
msbuild /m /clp:ForceConsoleColor /p:Configuration=Debug,Platform=x64,CppWinRTBuildVersion=1.2.3.4,Clang=1,PlatformToolset=ClangCl cppwinrt.sln /t:cppwinrt
msbuild /m /clp:ForceConsoleColor /p:Configuration=Debug,Platform=x64,CppWinRTBuildVersion=1.2.3.4,Clang=1,PlatformToolset=ClangCl cppwinrt.sln /t:test\test

I'm not sure if all 3 builds are necessary but that was enough to get the test\test directory to produce the same break as the CI build.

@dmachaj
Copy link
Contributor Author

dmachaj commented Apr 24, 2025

For some reason the Clang warnings wouldn't all print out at once. I had to keep fixing warnings and rebuilding until it was green. There were a bunch of clang-only warnings that were previously unknown (mostly minor, all in test code).

There was also an x86-only signed/unsigned mismatch in the format code that I have attempted to fix.

dmachaj added 2 commits April 25, 2025 10:59
…aller project to try and avoid memory exhaustion during link
dunhor
dunhor previously approved these changes Apr 25, 2025
@dmachaj dmachaj merged commit 46fd3ed into master Apr 25, 2025
75 checks passed
@dmachaj dmachaj deleted the user/dmachaj/warnings-as-errors branch April 25, 2025 18:39
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.

MSVC warns about use of __has_attribute

4 participants