Skip to content

Fix/wshadow warnings#733

Draft
Sajeev-D wants to merge 11 commits intometacall:developfrom
Sajeev-D:fix/wshadow-warnings
Draft

Fix/wshadow warnings#733
Sajeev-D wants to merge 11 commits intometacall:developfrom
Sajeev-D:fix/wshadow-warnings

Conversation

@Sajeev-D
Copy link
Copy Markdown

Description

Resolved all -Wshadow warnings in MetaCall's own codebase by adding -Wshadow in Warnings.cmake and making the following changes:

  • Renamed parameter scope to scope_name in configuration_create (configuration.c)
  • Renamed parameter loader to loader_ptr in metacall_handle_initialize,
    metacall_register_loaderv (metacall.c) and metacall_link_register_loader (metacall_link.c)
  • Renamed parameter context to ctx in function_mock_interface_await (mock_loader_impl.c)
    and related test files
  • Renamed local variable str to avoid shadowing parameter in value_from_string (reflect_value_type.c)
  • Renamed struct attribute_type to attribute_s to avoid shadowing by attribute_type() function
  • Renamed struct loader_impl_type to loader_impl_s to avoid shadowing by loader_impl_type() function

Remaining -Wshadow warnings in third-party dependency rapidjson/document.h are out of scope.

Only changed parameter/variable names, so formatting is unchanged.

Fixes #561 (Partially)

All 39 tests in the core test suite passed in both Debug mode and with Address Sanitizer (ASan) enabled.

image

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests/screenshots that prove my fix is effective
  • I have tested the tests implicated, and they pass

@viferga
Copy link
Copy Markdown
Member

viferga commented Mar 30, 2026

One question, how is loader_impl_type duplicated? This definition appears in many places.

@Sajeev-D
Copy link
Copy Markdown
Author

One question, how is loader_impl_type duplicated? This definition appears in many places.

The struct loader_impl_type was renamed to loader_impl_s since there is a namespace collision between the function
loader_impl_type() and the struct tag struct loader_impl_type. In C++, the struct tags enter the global namespace. Since we have a function named loader_impl_type, the compiler flags this as a shadow conflict. So I renamed the internal struct tags to _s to resolve this ambiguity without changing the public API function.

For reference, this was the warning that is resolved after making this change:

warning: 'type_type* loader_impl_type(loader_impl, const char*)' hides constructor for 'struct loader_impl_type' [-Wshadow]

@viferga
Copy link
Copy Markdown
Member

viferga commented Mar 31, 2026

I prefer if you change the function name instead:

LOADER_API type loader_impl_type(loader_impl impl, const char *name);

We can use loader_impl_get_type instead.

@viferga
Copy link
Copy Markdown
Member

viferga commented Mar 31, 2026

Also uncomment this:

#add_compile_options(-Wshadow)

@viferga viferga marked this pull request as draft April 1, 2026 06:55
@viferga viferga marked this pull request as draft April 1, 2026 06:55
@Sajeev-D
Copy link
Copy Markdown
Author

Sajeev-D commented Apr 2, 2026

I prefer if you change the function name instead:

LOADER_API type loader_impl_type(loader_impl impl, const char *name);

We can use loader_impl_get_type instead.

I renamed loader_impl_type function name to loader_impl_get_type and reverted loader_impl_s struct name back to loader_impl_type. All call sites and loaders have been updated accordingly.

Verified no regressions using debug build configuration with Address Sanitizer flag, and all tests passed.

image

@Sajeev-D
Copy link
Copy Markdown
Author

Sajeev-D commented Apr 2, 2026

Also uncomment this:

#add_compile_options(-Wshadow)

Uncommented -Wshadow compile option.

@Sajeev-D Sajeev-D marked this pull request as ready for review April 2, 2026 03:16
@viferga viferga marked this pull request as draft April 17, 2026 07:34
@viferga
Copy link
Copy Markdown
Member

viferga commented Apr 17, 2026

I will review it in detail, I'm leaving it as a draft untill then.

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.

Enable all compiler warnings and solve them (GCC, Clang, MSVC)

2 participants