Skip to content

fix: compiler warnings with no side effects#2933

Merged
bruno-dasilva merged 6 commits into
masterfrom
bruno/fix-warnings-3
Jun 2, 2026
Merged

fix: compiler warnings with no side effects#2933
bruno-dasilva merged 6 commits into
masterfrom
bruno/fix-warnings-3

Conversation

@bruno-dasilva

@bruno-dasilva bruno-dasilva commented Apr 18, 2026

Copy link
Copy Markdown
Collaborator

Purpose

Fix the warning spam when compiling with clang, gcc, or msvc (mostly clang). This PR focuses on the non-behaviour changing fixes to code, mostly formatting changes or implicit casts.

AI Disclosure

This PR was generated through running claude code in a loop to fix every warning. However, every non-trivial change was inspected and several "fixes" were dropped in favor of different solutions to try and keep backwards compatibility in mind. I've called out the couple places where I don't understand the fix or the implication of the fix to other reviewers.

@bruno-dasilva

bruno-dasilva commented Apr 18, 2026

Copy link
Copy Markdown
Collaborator Author

Comment thread rts/Lua/LuaParser.h
Comment thread rts/Sim/Path/HAPFS/PathingState.cpp Outdated
Comment thread rts/Sim/Projectiles/FlareProjectile.cpp Outdated
Comment thread rts/Sim/Units/Scripts/UnitScript.cpp
Comment thread rts/Sim/Units/UnitTypes/Builder.cpp
Comment thread rts/Sim/Projectiles/FlareProjectile.cpp Outdated
Comment thread rts/Lua/LuaOpenGL.cpp
Comment thread rts/Sim/Units/UnitTypes/Builder.cpp
@bruno-dasilva bruno-dasilva force-pushed the bruno/fix-warnings-3 branch 2 times, most recently from 2bd0c46 to 3cbd6c1 Compare April 22, 2026 22:36
Comment thread rts/Sim/Projectiles/FlareProjectile.cpp
@bruno-dasilva bruno-dasilva force-pushed the bruno/fix-warnings-2 branch from da5c07f to ab7b139 Compare May 27, 2026 18:26
@bruno-dasilva bruno-dasilva changed the base branch from bruno/fix-warnings-2 to master May 27, 2026 18:28
@bruno-dasilva bruno-dasilva force-pushed the bruno/fix-warnings-3 branch from 35ac9e8 to a634fdc Compare May 27, 2026 18:29
Comment thread CMakeLists.txt Outdated
Comment thread rts/Lua/LuaParser.h
Comment thread rts/System/type2.h Outdated
#ifdef USING_CREG
// creg_class specializations are defined in type2.cpp via CR_BIND_TEMPLATE
template<> creg::Class type2<int32_t>::creg_class;
template<> creg::Class type2<float>::creg_class;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what was the issue when these were missing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

oh sorry, here's the warning (one per instantiated type):

  rts/System/type2.h:12:2: warning: instantiation of variable 'type2<int>::creg_class' required here,
          but no definition is available [-Wundefined-var-template]
     12 |         CR_DECLARE_STRUCT(type2)
        |         ^
  rts/System/creg/creg.h:244:33: note: expanded from macro 'CR_DECLARE_STRUCT'
  rts/System/creg/creg.h:216:46: note: expanded from macro 'CR_DECLARE_BASE'
    216 |         static creg::Class* StaticClass() { return &creg_class; } \
  probe.cpp:2:39: note: in instantiation of member function 'type2<int>::StaticClass' requested here
  rts/System/type2.h:12:2: note: forward declaration of template entity is here
  rts/System/creg/creg.h:213:21: note: expanded from macro 'CR_DECLARE_BASE'
    213 |         static creg::Class creg_class; \
  rts/System/type2.h:12:2: note: add an explicit instantiation declaration to suppress this warning
          if 'type2<int>::creg_class' is explicitly instantiated in another translation unit

just telling the compiler explicitly not to worry about generating these, as they're hand-written elsewhere. I think it's a limitation of compilation seeing only one file at a time, but then these resolve at linking time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perhaps this should live in creg_cond.h then?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hm. Looking at cred_cond.h it's all type-agnostic creg plumbing, like its all macro definitions. Does it really make sense to put type2 stuff in there? Kinda inverts the dependency.

if you mean just factoring out the #ifdef USING_CREG we could write a helper macro in creg_cond.h that is something like #define CR_DECLARE_TEMPLATE_INSTANCE(TCls) template<> creg::Class TCls::creg_class

then in this type2 file you just use the macro:

CR_DECLARE_TEMPLATE_INSTANCE(int2)
CR_DECLARE_TEMPLATE_INSTANCE(float2)
...

wdyt?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

something like #define CR_DECLARE_TEMPLATE_INSTANCE(TCls) template<> creg::Class TCls::creg_class

Sounds alright.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

should be good now :)

Comment thread test/CMakeLists.txt
@bruno-dasilva bruno-dasilva force-pushed the bruno/fix-warnings-3 branch from a634fdc to 6ddbfda Compare May 28, 2026 11:33
@bruno-dasilva bruno-dasilva merged commit a6a8186 into master Jun 2, 2026
7 checks passed
@bruno-dasilva bruno-dasilva deleted the bruno/fix-warnings-3 branch June 2, 2026 14:17
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.

2 participants