error: in-class initializer for static data member is not a constant expression [clang-diagnostic-error]
まだ誰も着手していません。
評価
調査の方向性
../src/configuration.cpp の診断を再現し、その後、program_options/value_semantic.hpp を通るインスタンス化パスに沿って Boost の is_signed.hpp と is_unsigned.hpp を調査します。boost::log::trivial::severity_level とその default_value 呼び出しの動作を確認します。このケースで報告された Clang エラーが発生しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Code:
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
MPingSender::Configuration::Configuration(const std::span<char *> args)
{
boost::program_options::options_description options{"Configuration"};
// clang-format off
options.add_options()
("help", "Help screen")
("log-level", boost::program_options::value<boost::log::trivial::severity_level>(&this->_log_level)->default_value(boost::log::trivial::info), "Log level. Valid options are trace, debug, info, warning, error and fatal. Defaults to info.")
("bind-address", boost::program_options::value<std::string>(&this->_bind_address)->required(), "Address to which the UDP socket is bound. Required.")
("bind-port", boost::program_options::value<uint16_t>(&this->_bind_port)->default_value(4321), "Port to which the UDP socket is bound. Defaults to 4321.")
("address", boost::program_options::value<std::string>(&this->_address)->default_value("ff2e::42"), "Address to send packets to. Defaults to ff2e::42")
("port", boost::program_options::value<uint16_t>(&this->_port)->default_value(4321), "Address to which the packages are sent.")
("ttl", boost::program_options::value<uint8_t>(&this->_ttl)->default_value(64), "TTTL or hop limit with which the packets are sent. Defaults to 64.")
("interface-name", boost::program_options::value<std::string>(&this->_interface_name)->required(), "Name of the interface from which the packets are sent. Required.")
;
// clang-format on
boost::program_options::command_line_parser parser{
static_cast<int>(args.size()), args.data()};
parser.options(options).allow_unregistered().style(
boost::program_options::command_line_style::allow_long |
boost::program_options::command_line_style::allow_sticky |
boost::program_options::command_line_style::long_allow_next);
const boost::program_options::parsed_options parsed_options = parser.run();
boost::program_options::variables_map vm;
store(parsed_options, vm);
this->_help = vm.contains("help");
if (this->_help)
{
std::clog << "mping-sender" << std::endl
<< std::endl
<< "Usage: mping-sender [configuration]" << std::endl
<< std::endl
<< options << std::endl;
std::exit(EXIT_SUCCESS); // NOLINT(concurrency-mt-unsafe)
}
notify(vm);
boost::log::core::get()->set_filter(boost::log::trivial::severity >=
this->_log_level);
}
// NOLINTEND(cppcoreguidelines-pro-type-member-init)
class Configuration
{
public:
explicit Configuration(const std::span<char *> args);
[[nodiscard]] bool get_help() const noexcept;
[[nodiscard]] boost::log::trivial::severity_level
get_log_level() const noexcept;
[[nodiscard]] std::string get_bind_address() const noexcept;
[[nodiscard]] uint16_t get_bind_port() const noexcept;
[[nodiscard]] std::string get_address() const noexcept;
[[nodiscard]] uint16_t get_port() const noexcept;
[[nodiscard]] uint8_t get_ttl() const noexcept;
[[nodiscard]] std::string get_interface_name() const noexcept;
void apply_log_level() const;
private:
bool _help;
boost::log::trivial::severity_level _log_level;
std::string _bind_address;
uint16_t _bind_port;
std::string _address;
uint16_t _port;
uint8_t _ttl;
std::string _interface_name;
};
generates a clang-diagnostic-error:
>>> /usr/bin/clang-tidy --use-color -quiet -p /home/marek/git/mping-sender/build /home/marek/git/mping-sender/src/configuration.cpp
190715 warnings and 2 errors generated.
Error while processing /home/marek/git/mping-sender/src/configuration.cpp.
381430 warnings and 4 errors generated.
Error while processing /home/marek/git/mping-sender/src/configuration.cpp.
/usr/include/boost/type_traits/is_signed.hpp:37:25: error: in-class initializer for static data member is not a constant expression [clang-diagnostic-error]
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/boost/type_traits/is_signed.hpp:45:60: note: in instantiation of template class 'boost::detail::is_signed_values<boost::log::trivial::severity_level>' requested here
45 | BOOST_STATIC_CONSTANT(bool, value = (!(::boost::detail::is_signed_values<T>::minus_one > boost::detail::is_signed_values<T>::zero)));
| ^
/usr/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/include/boost/type_traits/is_signed.hpp:74:40: note: in instantiation of template class 'boost::detail::is_signed_helper<boost::log::trivial::severity_level>' requested here
74 | BOOST_STATIC_CONSTANT(bool, value = type::value);
| ^
/usr/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/include/boost/type_traits/is_signed.hpp:79:85: note: in instantiation of template class 'boost::detail::is_signed_impl<boost::log::trivial::severity_level>' requested here
79 | template <class T> struct is_signed : public integral_constant<bool, boost::detail::is_signed_impl<T>::value> {};
| ^
/usr/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:315:44: note: in instantiation of template class 'boost::is_signed<boost::log::trivial::severity_level>' requested here
315 | typename boost::enable_if_c<boost::is_signed<Type>::value && !boost::is_enum<Type>::value, bool>::type
| ^
/usr/include/boost/lexical_cast/detail/converter_lexical.hpp:449:67: note: while substituting deduced template arguments into function template 'stream_in' [with Type = boost::log::trivial::severity_level]
449 | -> decltype(std::declval<optimized_src_stream&>().stream_in(std::declval<lcast::exact<T>>()), optimized_src_stream{});
| ^
/usr/include/boost/lexical_cast/detail/converter_lexical.hpp:454:46: note: while substituting explicitly-specified template arguments into function template 'detect_type'
454 | using from_src_stream = decltype(detect_type<Source>(1));
| ^
/usr/include/boost/lexical_cast/try_lexical_convert.hpp:67:20: note: in instantiation of template class 'boost::detail::lexical_converter_impl<std::basic_string<char>, boost::log::trivial::severity_level>' requested here
67 | return caster_type::try_convert(arg, result);
| ^
/usr/include/boost/lexical_cast.hpp:42:41: note: in instantiation of function template specialization 'boost::conversion::detail::try_lexical_convert<std::basic_string<char>, boost::log::trivial::severity_level>' requested here
42 | if (!boost::conversion::detail::try_lexical_convert(arg, result)) {
| ^
/usr/include/boost/program_options/value_semantic.hpp:202:46: note: in instantiation of function template specialization 'boost::lexical_cast<std::basic_string<char>, boost::log::trivial::severity_level>' requested here
202 | m_default_value_as_text = boost::lexical_cast<std::string>(v);
| ^
../src/configuration.cpp:16:108: note: in instantiation of member function 'boost::program_options::typed_value<boost::log::trivial::severity_level>::default_value' requested here
16 | ("log-level", boost::program_options::value<boost::log::trivial::severity_level>(&this->_log_level)->default_value(boost::log::trivial::info), "Log level. Valid options are trace, debug, info, warning, error and fatal. Defaults to info.")
| ^
/usr/include/boost/type_traits/is_signed.hpp:37:38: note: integer value -1 is outside the valid range of values [0, 7] for the enumeration type 'severity_level'
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^
/usr/include/boost/type_traits/is_unsigned.hpp:38:25: error: in-class initializer for static data member is not a constant expression [clang-diagnostic-error]
38 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/boost/type_traits/is_unsigned.hpp:45:58: note: in instantiation of template class 'boost::detail::is_unsigned_values<boost::log::trivial::severity_level>' requested here
45 | BOOST_STATIC_CONSTANT(bool, value = (::boost::detail::is_unsigned_values<T>::minus_one > ::boost::detail::is_unsigned_values<T>::zero));
| ^
/usr/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/include/boost/type_traits/is_unsigned.hpp:74:40: note: in instantiation of template class 'boost::detail::is_ununsigned_helper<boost::log::trivial::severity_level>' requested here
74 | BOOST_STATIC_CONSTANT(bool, value = type::value);
| ^
/usr/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/include/boost/type_traits/is_unsigned.hpp:79:87: note: in instantiation of template class 'boost::detail::is_unsigned<boost::log::trivial::severity_level>' requested here
79 | template <class T> struct is_unsigned : public integral_constant<bool, boost::detail::is_unsigned<T>::value> {};
| ^
/usr/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:319:44: note: in instantiation of template class 'boost::is_unsigned<boost::log::trivial::severity_level>' requested here
319 | typename boost::enable_if_c<boost::is_unsigned<Type>::value && !boost::is_enum<Type>::value, bool>::type
| ^
/usr/include/boost/lexical_cast/detail/converter_lexical.hpp:449:67: note: while substituting deduced template arguments into function template 'stream_in' [with Type = boost::log::trivial::severity_level]
449 | -> decltype(std::declval<optimized_src_stream&>().stream_in(std::declval<lcast::exact<T>>()), optimized_src_stream{});
| ^
/usr/include/boost/lexical_cast/detail/converter_lexical.hpp:454:46: note: while substituting explicitly-specified template arguments into function template 'detect_type'
454 | using from_src_stream = decltype(detect_type<Source>(1));
| ^
/usr/include/boost/lexical_cast/try_lexical_convert.hpp:67:20: note: in instantiation of template class 'boost::detail::lexical_converter_impl<std::basic_string<char>, boost::log::trivial::severity_level>' requested here
67 | return caster_type::try_convert(arg, result);
| ^
/usr/include/boost/lexical_cast.hpp:42:41: note: in instantiation of function template specialization 'boost::conversion::detail::try_lexical_convert<std::basic_string<char>, boost::log::trivial::severity_level>' requested here
42 | if (!boost::conversion::detail::try_lexical_convert(arg, result)) {
| ^
/usr/include/boost/program_options/value_semantic.hpp:202:46: note: in instantiation of function template specialization 'boost::lexical_cast<std::basic_string<char>, boost::log::trivial::severity_level>' requested here
202 | m_default_value_as_text = boost::lexical_cast<std::string>(v);
| ^
../src/configuration.cpp:16:108: note: in instantiation of member function 'boost::program_options::typed_value<boost::log::trivial::severity_level>::default_value' requested here
16 | ("log-level", boost::program_options::value<boost::log::trivial::severity_level>(&this->_log_level)->default_value(boost::log::trivial::info), "Log level. Valid options are trace, debug, info, warning, error and fatal. Defaults to info.")
| ^
/usr/include/boost/type_traits/is_unsigned.hpp:38:38: note: integer value -1 is outside the valid range of values [0, 7] for the enumeration type 'severity_level'
38 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
|
- 主要言語
- HTML
- スター
- 8.6k
- フォーク
- 2k
- 平均マージ
- 9時間 35分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
boostorg/boost のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
sagemathinc/sagebrush#1683 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
baseballyama/rsvelte#5235 ·
メンテナーはふだん 1 日以内に返信
-
lang-core: member access on a component instance reads its internal fields instead of giving nullオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
midspiral/LemmaScript#355 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信