Skip to content
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

Block unsafe use of SetDParamStr #10136

Merged
merged 1 commit into from Nov 5, 2022

Conversation

frosch123
Copy link
Member

@frosch123 frosch123 commented Nov 5, 2022

Motivation / Problem

#10130 fixes a single case of incorrect usage of SetDParamStr.

Description

This PR deletes the problematic overload/implicit conversion, so issues like #10130 no longer compile:

GCC and derivates:

src/settings.cpp: In function ‘GRFConfig* GRFLoadConfig(IniFile&, const char*, bool)’:
src/settings.cpp:1019:62: error: use of deleted function ‘void SetDParamStr(uint, std::string&&)’
 1019 |    SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
      |                                                              ^
In file included from src/ai/../script/../textfile_gui.h:14,
                 from src/ai/../script/script_config.hpp:18,
                 from src/ai/ai_config.hpp:13,
                 from src/settings.cpp:42:
src/ai/../script/../strings_func.h:206:6: note: declared here
  206 | void SetDParamStr(uint n, std::string &&str) = delete; // block passing temporaries to SetDParamStr
      |      ^~~~~~~~~~~~

Clang and derivates:

Error: src/settings.cpp:1019:4: error: call to deleted function 'SetDParamStr'
                          SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
                          ^~~~~~~~~~~~
  src/strings_func.h:206:6: note: candidate function has been explicitly deleted
  void SetDParamStr(uint n, std::string &&str) = delete; // block passing temporaries to SetDParamStr
       ^
  src/strings_func.h:205:6: note: candidate function
  void SetDParamStr(uint n, const std::string &str);
       ^
  src/strings_func.h:204:6: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char>>') to 'const char *' for 2nd argument
  void SetDParamStr(uint n, const char *str);
       ^

MSVC

  Error: src\settings.cpp(1019): error C2280: 'void SetDParamStr(uint,std::string &&)': attempting to reference a deleted function
  src\strings_func.h(206): note: see declaration of 'SetDParamStr'
  src\strings_func.h(206): note: 'void SetDParamStr(uint,std::string &&)': function was explicitly deleted

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@glx22
Copy link
Contributor

glx22 commented Nov 5, 2022

Every target failed as expected.

@frosch123 frosch123 merged commit fea6a34 into OpenTTD:master Nov 5, 2022
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.

None yet

2 participants