hl2sdk icon indicating copy to clipboard operation
hl2sdk copied to clipboard

[CS:GO] Fix compilation errors for std=c++2a

Open mixern6 opened this issue 1 year ago • 6 comments

The PR fixes these compilation errors:

  • error: increment of object of volatile-qualified type 'volatile int' is deprecated
  • error: ISO C++17 does not allow 'register' storage class specifier
  • error: too many arguments provided to function-like macro invocation clamp

Explanation:

  • Incrementing of a volatile type is deprecated but can be replaced with assignment of the incremented value.
  • Register storage is not allowed, but it is just a hint and the keyword can be safely removed: https://stackoverflow.com/a/3207025/18259736
  • The clamp macro is no longer required and can be excluded: https://www.mail-archive.com/[email protected]/msg474109.html

mixern6 avatar Oct 01 '23 20:10 mixern6

You probably wanted to target cs2 branch instead of csgo?

GAMMACASE avatar Oct 02 '23 08:10 GAMMACASE

It is relevant for CS2 too, but I'd like to sort out these problems for CS:GO before moving on to CS2

mixern6 avatar Oct 02 '23 10:10 mixern6

The ifdef around the clamp wouldn't cover all the cases, as earlier cpp versions also could trigger. The macro would later conflict with libraries like algorithm, you can btw remove it completely as I see there's a clamp function defined in basetypes.h in hl2sdk codebase so it gets picked up.

GAMMACASE avatar Oct 02 '23 11:10 GAMMACASE

The ifdef around the clamp wouldn't cover all the cases, as earlier cpp versions also could trigger. The macro would later conflict with libraries like algorithm, you can btw remove it completely as I see there's a clamp function defined in basetypes.h in hl2sdk codebase so it gets picked up.

Removed the clamp definition. SourceMod building finishes without errors.

mixern6 avatar Oct 02 '23 11:10 mixern6

I can't merge the csgo pr's, but by any chance if you are able to duplicate it also to the cs2 branch I'll merge that in as cs2 is the same in this regard. Otherwise looks good to me.

GAMMACASE avatar Oct 02 '23 11:10 GAMMACASE

I can't merge the csgo pr's, but by any chance if you are able to duplicate it also to the cs2 branch I'll merge that in as cs2 is the same in this regard. Otherwise looks good to me.

What will happen to this PR? I see the problem is relevant for all the other SDK's. Can the fix be merged to all of them? Shall I create a separate PR for each SDK?

@GAMMACASE Could you please cherry-pick this change to all the branches?

mixern6 avatar Oct 02 '23 13:10 mixern6