error: in-class initializer for static data member is not a constant expression [clang-diagnostic-error]

Aperta
#1,107 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
compilers

Direzione di ricerca

Riproduci la diagnostica da ../src/configuration.cpp, quindi ispeziona is_signed.hpp e is_unsigned.hpp di Boost lungo il percorso di istanziazione attraverso program_options/value_semantic.hpp. Conferma il comportamento di boost::log::trivial::severity_level e della sua chiamata a default_value; il lavoro è completato quando gli errori di Clang segnalati non si verificano più per questo caso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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));
      |        
Lingua principale
HTML
Stelle
8.6k
Fork
2k
Merge medio
9h 35m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di boostorg/boost

Tutte le issue di boostorg/boost

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.