Skip to content

Commit 579feb3

Browse files
committed
Core: Add [[nodiscard]] to string-like classes
1 parent 6a6a116 commit 579feb3

File tree

12 files changed

+22
-21
lines changed

12 files changed

+22
-21
lines changed

core/io/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ void Image::initialize_data(const char **p_xpm) {
22662266
switch (status) {
22672267
case READING_HEADER: {
22682268
String line_str = line_ptr;
2269-
line_str.replace_char('\t', ' ');
2269+
line_str = line_str.replace_char('\t', ' ');
22702270

22712271
size_width = line_str.get_slicec(' ', 0).to_int();
22722272
size_height = line_str.get_slicec(' ', 1).to_int();

core/io/ip_address.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#include "core/string/ustring.h"
3434

35-
struct IPAddress {
35+
struct [[nodiscard]] IPAddress {
3636
private:
3737
union {
3838
uint8_t field8[16];

core/io/resource_format_binary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ String ResourceLoaderBinary::recognize_script_class(Ref<FileAccess> p_f) {
11951195
return "";
11961196
}
11971197

1198-
get_unicode_string(); // type
1198+
_ALLOW_DISCARD_ get_unicode_string(); // type
11991199

12001200
f->get_64(); // Metadata offset
12011201
uint32_t flags = f->get_32();

core/string/node_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "core/string/string_name.h"
3434
#include "core/string/ustring.h"
3535

36-
class NodePath {
36+
class [[nodiscard]] NodePath {
3737
struct Data {
3838
SafeRefCount refcount;
3939
Vector<StringName> path;

core/string/string_name.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
class Main;
3939

40-
class StringName {
40+
class [[nodiscard]] StringName {
4141
struct Table;
4242

4343
struct _Data {

core/string/ustring.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ constexpr int64_t str_compare(const L *l_ptr, const R *r_ptr) {
127127
/*************************************************************************/
128128

129129
template <typename T>
130-
class CharProxy {
130+
class [[nodiscard]] CharProxy {
131131
friend String;
132132
friend CharStringT<T>;
133133

@@ -170,7 +170,7 @@ class CharProxy {
170170
/*************************************************************************/
171171

172172
template <typename T>
173-
class CharStringT {
173+
class [[nodiscard]] CharStringT {
174174
CowData<T> _cowdata;
175175
static constexpr T _null = 0;
176176

@@ -265,7 +265,7 @@ using Char16String = CharStringT<char16_t>;
265265
/* String */
266266
/*************************************************************************/
267267

268-
class String {
268+
class [[nodiscard]] String {
269269
CowData<char32_t> _cowdata;
270270
static constexpr char32_t _null = 0;
271271
static constexpr char32_t _replacement_char = 0xfffd;

editor/script_create_dialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static String _get_parent_class_of_script(const String &p_path) {
5959

6060
// Inherits from a built-in class.
6161
if (base.is_null()) {
62-
script->get_language()->get_global_class_name(script->get_path(), &class_name);
62+
// We only care about the referenced class_name.
63+
_ALLOW_DISCARD_ script->get_language()->get_global_class_name(script->get_path(), &class_name);
6364
return class_name;
6465
}
6566

modules/gdscript/gdscript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,8 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
28542854
if (subclass->extends_used) {
28552855
if (!subclass->extends_path.is_empty()) {
28562856
if (subclass->extends.is_empty()) {
2857-
get_global_class_name(subclass->extends_path, r_base_type);
2857+
// We only care about the referenced class_name.
2858+
_ALLOW_DISCARD_ get_global_class_name(subclass->extends_path, r_base_type);
28582859
subclass = nullptr;
28592860
break;
28602861
} else {

modules/gdscript/language_server/gdscript_workspace.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ bool GDScriptWorkspace::can_rename(const LSP::TextDocumentPositionParams &p_doc_
489489

490490
String path = get_file_path(p_doc_pos.textDocument.uri);
491491
if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
492-
parser->get_identifier_under_position(p_doc_pos.position, r_range);
492+
// We only care about the range.
493+
_ALLOW_DISCARD_ parser->get_identifier_under_position(p_doc_pos.position, r_range);
493494
r_symbol = *reference_symbol;
494495
return true;
495496
}
@@ -847,9 +848,7 @@ Error GDScriptWorkspace::resolve_signature(const LSP::TextDocumentPositionParams
847848
return ERR_METHOD_NOT_FOUND;
848849
}
849850

850-
GDScriptWorkspace::GDScriptWorkspace() {
851-
ProjectSettings::get_singleton()->get_resource_path();
852-
}
851+
GDScriptWorkspace::GDScriptWorkspace() {}
853852

854853
GDScriptWorkspace::~GDScriptWorkspace() {
855854
HashSet<String> cached_parsers;

scene/resources/animation_library.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ bool AnimationLibrary::is_valid_library_name(const String &p_name) {
4141
}
4242

4343
String AnimationLibrary::validate_library_name(const String &p_name) {
44-
String name = p_name;
45-
static const char *characters = "/:,[";
46-
name.replace_chars(characters, '_');
47-
return name;
44+
return p_name.replace_chars("/:,[", '_');
4845
}
4946

5047
Error AnimationLibrary::add_animation(const StringName &p_name, const Ref<Animation> &p_animation) {

0 commit comments

Comments
 (0)