Skip to content

Make the code compile with clang-cl in VS22 #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Caball009
Copy link

@Caball009 Caball009 commented May 20, 2025

I'm making this a draft for the time being because there are some things that still need doing:

  1. Resolve Fix StringClass POD Misclassification in MSVC/clang-cl #863, although I went ahead and wrote the code as I suggested there would be best for consistency.
  2. Resolve Clang-cl's optimizer causes the game to exit unnecessarily #866, this could be as simple as a macro for clang around the exit. I'd like to be notified if this path is taken, though, and this path isn't taken in debug mode.
  3. Check compatibility with VC6.
  4. The GameSpy dependency has a sub-project (gt2) which cannot easily be compiled with clang-cl. There seems to be an issue around the macro va_arg which gets a different definition with clang-cl.
  5. Some CMake scripts need to be adjusted to add the option to compile with clang-cl, and the compiler setting needs to be changed for that flag.

I have only resolved the compiler errors for g_generals, z_generals and dependencies for both projects.

@Caball009 Caball009 marked this pull request as ready for review May 20, 2025 20:20
@Caball009 Caball009 marked this pull request as draft May 20, 2025 20:20
@Caball009 Caball009 changed the title Make the code compile with clang-cl Make the code compile with clang-cl in VS22 May 20, 2025
@@ -590,7 +590,7 @@ void WWProfileManager::End_Collecting(const char* filename)
if (name[i]==',') name[i]='.';
if (name[i]==';') name[i]=':';
}
str.Format("ID: %d %s\r\n",ite.Peek_Value(),name);
str.Format("ID: %d %s\r\n",ite.Peek_Value(),name.Peek_Buffer());

Choose a reason for hiding this comment

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

Correct way to get a C string from StringClass is to use static_cast<const char *>(name) to invoke the conversion operator.

Copy link
Author

Choose a reason for hiding this comment

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

I'd like to hear from one or more other contributors on this because I think consistency is a valid counter point.

@@ -32,7 +32,7 @@
#define IUNKNOWN_NOEXCEPT
#endif

#if __cplusplus >= 201103L
#if __cplusplus >= 201103L && !defined(__clang__)

Choose a reason for hiding this comment

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

This doesn't sit right with me, cland-cl should be able to handle these constructs in C++11 or greater.

Copy link
Author

@Caball009 Caball009 May 21, 2025

Choose a reason for hiding this comment

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

I couldn't really figure out what was going on, frankly, I think clang-cl doesn't like forward declared enums with fixed underlying type, but that doesn't really make sense to me.

@@ -172,19 +172,19 @@ void W3DMainMenuDraw( GameWindow *window, WinInstanceData *instData )
IRegion2D topHorizontal1 ={pos.x, pos.y, pos.x + size.x, pos.y };
IRegion2D topHorizontal1drop ={pos.x, pos.y+1, pos.x + size.x, pos.y+1 };

IRegion2D topHorizontal2 ={pos.x, pos.y + (size.y * .1) , pos.x + size.x, pos.y + (size.y * .1) };
IRegion2D topHorizontal2drop ={pos.x, pos.y + (size.y * .12) , pos.x + size.x, pos.y + (size.y * .12) };
IRegion2D topHorizontal2 ={pos.x, pos.y + static_cast<Int>(size.y * .1) , pos.x + size.x, pos.y + static_cast<Int>(size.y * .1) };

Choose a reason for hiding this comment

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

Doesn't this change the way the maths is done? Originally the values in parenthesis would be implictly promoted to double and then the addition done using double precision as well before final conversion back to Int. Now the addition will be done using integer addition.

Copy link
Author

Choose a reason for hiding this comment

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

I'll look into this.

@OmniBlade
Copy link

For the GameSpy SDK issue, you can log the issue or create a PR for it at https://github.com/TheAssemblyArmada/GamespySDK and then PR bumping the version that is fetched here. At a glance it looks like the macros to take the "Unix" path aren't hit so __clang__ needs adding to the checks to stop it compiling the none standard adhearing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants