llvm / llvm/llvm-project

[libc] Was it intended to name constructor parameters identically to members?

Open
#163,677 5 comments 0 reactions 0 assignees View on GitHub
libc question
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently, in libc, there're some constructor parameters of identical names to members. They constantly trigger warning when compiled with GCC.

https://github.com/llvm/llvm-project/blob/082efbaac1b706bcdae624243465268ca23d1655/libc/src/__support/sign.h#L35-L36

https://github.com/llvm/llvm-project/blob/082efbaac1b706bcdae624243465268ca23d1655/libc/src/__support/FPUtil/FPBits.h#L213

https://github.com/llvm/llvm-project/blob/082efbaac1b706bcdae624243465268ca23d1655/libc/src/__support/str_to_num_result.h#L35-L40

Example in libc++ CI with GCC

```
[1963/2000] /usr/bin/g++-15 -DLIBCXX_BUILDING_LIBCXXABI -DLIBC_NAMESPACE=__llvm_libc_common_utils -D_GLIBCXX_USE_CXX11_ABI=1 -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/gha/actions-runner/_work/llvm-project/llvm-project/libcxx/src -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/generic-gcc/include/c++/v1 -I/home/gha/actions-runner/_work/llvm-project/llvm-project/libcxxabi/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-dangling-reference -Wno-redundant-move -Wno-pessimizing-move -Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-inden
In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/FPUtil/FPBits.h:27,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/shared/fp_bits.h:13,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/libcxx/src/include/from_chars_floating_point.h:13,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/libcxx/src/charconv.cpp:12:
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/sign.h: In constructor 'constexpr __llvm_libc_common_utils::Sign::Sign(bool)':
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/sign.h:35:44: warning: declaration of 'is_negative' shadows a member of '__llvm_libc_common_utils::Sign' [-Wshadow]
35 | LIBC_INLINE constexpr explicit Sign(bool is_negative)
| ~~~~~^~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/sign.h:38:8: note: shadowed declaration is here
38 | bool is_negative;
| ^~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/FPUtil/FPBits.h: In constructor 'constexpr __llvm_libc_common_utils::fputil::internal::FPStorage::TypedInt::TypedInt(T)':
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/FPUtil/FPBits.h:213:47: warning: declaration of 'value' shadows a member of '__llvm_libc_common_utils::fputil::internal::FPStorage::TypedInt' [-Wshadow]
213 | LIBC_INLINE constexpr explicit TypedInt(T value) : value(value) {}
| ~~^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/FPUtil/FPBits.h:231:7: note: shadowed declaration is here
231 | T value;
| ^~~~~
In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_integer.h:26,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/high_precision_decimal.h:22,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_float.h:29,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/shared/str_to_float.h:13,
from /home/gha/actions-runner/_work/llvm-project/llvm-project/libcxx/src/include/from_chars_floating_point.h:14:
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h: In constructor 'constexpr __llvm_libc_common_utils::StrToNumResult::StrToNumResult(T)':
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:35:42: warning: declaration of 'value' shadows a member of '__llvm_libc_common_utils::StrToNumResult' [-Wshadow]
35 | LIBC_INLINE constexpr StrToNumResult(T value)
| ~~^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:31:5: note: shadowed declaration is here
31 | T value;
| ^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h: In constructor 'constexpr __llvm_libc_common_utils::StrToNumResult::StrToNumResult(T, ptrdiff_t)':
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:37:59: warning: declaration of 'parsed_len' shadows a member of '__llvm_libc_common_utils::StrToNumResult' [-Wshadow]
37 | LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len)
| ~~~~~~~~~~^~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:33:13: note: shadowed declaration is here
33 | ptrdiff_t parsed_len;
| ^~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:37:42: warning: declaration of 'value' shadows a member of '__llvm_libc_common_utils::StrToNumResult' [-Wshadow]
37 | LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len)
| ~~^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:31:5: note: shadowed declaration is here
31 | T value;
| ^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h: In constructor 'constexpr __llvm_libc_common_utils::StrToNumResult::StrToNumResult(T, ptrdiff_t, int)':
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:39:75: warning: declaration of 'error' shadows a member of '__llvm_libc_common_utils::StrToNumResult' [-Wshadow]
39 | LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
| ~~~~^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:32:7: note: shadowed declaration is here
32 | int error;
| ^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:39:59: warning: declaration of 'parsed_len' shadows a member of '__llvm_libc_common_utils::StrToNumResult' [-Wshadow]
39 | LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
| ~~~~~~~~~~^~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:33:13: note: shadowed declaration is here
33 | ptrdiff_t parsed_len;
| ^~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:39:42: warning: declaration of 'value' shadows a member of '__llvm_libc_common_utils::StrToNumResult' [-Wshadow]
39 | LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
| ~~^~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/cmake/Modules/../../libc/src/__support/str_to_num_result.h:31:5: note: shadowed declaration is here
31 | T value;
| ^~~~~
At global scope:
cc1plus: note: unrecognized command-line option '-Wno-nullability-completeness' may have been intended to silence earlier diagnostics
```

Is such pattern intended?

Contributor guide

Open the contributing guide

Research direction

Start with the constructors referenced in libc/src/__support/sign.h, libc/src/__support/FPUtil/FPBits.h, and libc/src/__support/str_to_num_result.h. Review the GCC -Wshadow diagnostics and determine whether the parameter naming is intentional. Done means the affected constructors no longer trigger these shadowing warnings while preserving their behavior; verify with the relevant GCC libc or libc++ build.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.