Skip to content

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

@frederick-vs-ja

Description

@frederick-vs-ja

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

LIBC_INLINE constexpr explicit Sign(bool is_negative)
: is_negative(is_negative) {}

LIBC_INLINE constexpr explicit TypedInt(T value) : value(value) {}

LIBC_INLINE constexpr StrToNumResult(T value)
: value(value), error(0), parsed_len(0) {}
LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len)
: value(value), error(0), parsed_len(parsed_len) {}
LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
: value(value), error(error), parsed_len(parsed_len) {}

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<fp_type>::TypedInt<T>::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<fp_type>::TypedInt<T>' [-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<T>::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<T>' [-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<T>::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<T>' [-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<T>' [-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<T>::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<T>' [-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<T>' [-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<T>' [-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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    libcquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions