std::string_view rvalue from macro not a constant expression when building on ARM using GCC

  arm, c++, c++20, gcc, raspberry-pi

I have an issue building my library for ARM. Note that this code builds and runs fine when building for x86.

I have a macro:

#define LOG_WARN(logger, message, ...) if (logger) { logger-Warn(message, __VA_ARGS__); }

I use it in the code like this:

LOG_WARN(_logger, "This is a log message {:d}.", _id);

And it calls a template member function of my logger class (which is a wrapper for spdlog).

template <typename... Args>
void Warn(const std::string_view &&message, Args &&...args) const
{
    _logger->warn(message, std::forward<Args>(args)...);
}

I am building with cmake 3.16.3 and gcc 10.3.0 (from the Ubuntu 20.04 repo) on a raspberry pi 4:

SpdLogLogger.h: In instantiation of ‘void SpdLogLogger::Info(const string_view&&, Args&& ...) const [with Args = {const long unsigned int&}; std::string_view = std::basic_string_view<char>]’:
CallingCode.cpp:34:9:   required from here
SpdLogLogger.h:67:22: error: ‘message’ is not a constant expression
   67 |         _logger->info(message, std::forward<Args>(args)...);
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now interestingly, manually expanding the macro compiles fine. I think this is a bug with the ARM version of gcc/g++ but wanted to run this by others to see if it is anything I might be doing.

Source: Windows Questions C++

LEAVE A COMMENT