1

A static code analysis tool shows me that I have an unsequenced function calls for a define. Want to get rid of the warning.

It complains that I use Logging() and get_id() (two functions, only one allowed) in the last define.

#define MSG_FORMAT(x) " [thread: " << std::this_thread::get_id() << "] [" << __func__ << "] " << x

#define SYSTEM_LOG(x) loa::peer::Logging() << MSG_FORMAT(x)

How can I modify the defines to avoid the warning? As you see I have already tried to split them into two defines.

Claudio
  • 10,614
  • 4
  • 31
  • 71
Sharky
  • 323
  • 1
  • 3
  • 11
  • 1
    This looks like a really bad idea. Why do you use macros? Please create an [MCVE](https://stackoverflow.com/help/reprex). How do you use the macro? Where do you use the macro? With what parameter? What is the context? `code analysis tool shows me` - what tool? and what is the exact warning message, including filename and line number? – KamilCuk May 15 '19 at 11:03
  • 4
    The unsequencedness shouldn't matter. Silly warning. Just disable it! – Lightness Races in Orbit May 15 '19 at 11:12
  • 5
    @KamilCuk "Why do you use macros?" - should be obvious from the code that he wants to include the function name in every log message, which necessitates a macro. – VLL May 15 '19 at 11:20
  • I'm guessing that you want to allow further chaining of `<<`? (Such as `SYSTEM_LOG("foo") << 123 << "abc";`) – molbdnilo May 15 '19 at 12:45
  • 1
    Since macros are resolved at (or, traditionally, *before*) compile time, splitting the macro can’t possibly introduce ordering on a runtime operation. – Davis Herring May 15 '19 at 13:15
  • Thank you for all answers. In the future, this code will be exchanged with a proper logger (company generic c++ logger) but I wanted to know if the warning was an issue for the coming release. For now I will try to justify the warning. – Sharky May 16 '19 at 13:40

0 Answers0