Mismatch between C++17 and C++20, const char* no longer a constant expression

66 Views Asked by At

I have a project where I use the spdlog library. My header file looks like this:

#pragma once

#include <memory>
#include <string>
#include <spdlog/spdlog.h>

namespace vtek
{
    void initialize_logging(const InitInfo* info);
    void terminate_logging();
    void disable_logging();

    void flush_vtek_logger();
    void flush_client_logger();

    class LogContainer
    {
    public:
        static inline std::shared_ptr<spdlog::logger> sVtekLogger = nullptr;
        static inline std::shared_ptr<spdlog::logger> sClientLogger = nullptr;
    };
}

template<typename... Args>
inline void vtek_log_error(const char* message, const Args &... args)
{
    vtek::LogContainer::sVtekLogger->error(message, args...);
}

This code is working fine. I can include the header in any compilation unit and write vtek_log_error("Error, wrong parameter: {}", myParam);, and the templates in the logging header will figure out the rest.

Then I update the project (CMake settings) from C++17 to C++20, and this no longer works, and I don't really understand the compiler's message:

in ‘constexpr’ expansion of ‘fmt::v9::basic_format_string<char, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, const long unsigned int&>(message)’
/<path>/vtek_logging.h:97:47: error: ‘message’ is not a constant expression
   97 |         vtek::LogContainer::sVtekLogger->error(message, args...);

Why is message no longer a constant expression? It looks pretty "constant" to me, ie. vtek_log_error("A constant message of type const char*");

Is this a known problem? Or do I need to provide more information?

0

There are 0 best solutions below