KEMBAR78
DIRECTOR: Really fix warning by criezy · Pull Request #4722 · scummvm/scummvm · GitHub
Skip to content

Conversation

@criezy
Copy link
Member

@criezy criezy commented Feb 18, 2023

The purpose of Common::remove_const (and std::remove_const outside of ScummVM` is not to remove the const specifier from a variable, but to remove it from a type and define a non-const type in the process. It is typically use in template code, such as this example given by @lephilousophe on Discord (thanks, that saved me the trouble of creating one myself 😄 ):

template<typename T>
class Test {
  Common::remove_const<T> mutable_item;
  T *array;
}

The previous commit to fix the warning thus did not fix anything as the code was still doing a C cast from a const type to a non-const one to remove the const specifier from the byte array. The proper way to fix that warning is to use a const_cast, as done in this pull request.

The main reason I am not committing this directly and opening a pull request is to give it more visibility, as I am sure more developers might be confused by the purpose of Common::remove_const and use it incorrectly .

The purpose of Common::remove_const is not to remove the const
specifier from a variable, but to remove it from a type and define
a non-const type in the process. The previous commit to fix the
warning thus did not fix anything as the code was still doing a
C cast to remove the const specifier. The proper way to fix that
warning is to use a const_cast.
@sev-
Copy link
Member

sev- commented Feb 20, 2023

Thank you! I misused the feature.

@sev- sev- merged commit a438bb6 into scummvm:master Feb 20, 2023
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