How to ignore a specific gcc warning that [is enabled by default]?

I have the following program that prints green text to the terminal:

#include <iostream>
#include <string>

//returns a colored string for terminal output streams
std::string colorize_forground(std::string const& message, int const& background) {
    return std::string("\e[38;5;" + std::to_string(background) + "m" + message + "\x1b[0m");
}

int main() {
    std::cout << colorize_forground("hello world in green", 106) << '\n';
}

However, when I compile the program with the following warning flag,

g ++ -std = C ++ 1y -pedantic -o main prob.cpp

I get this warning:

main.cpp: In function β€˜std::string colorize_forground(const string&, const int&)’:
main.cpp:6:21: warning: non-ISO-standard escape sequence, '\e' [enabled by default]
  return std::string("\e[38;5;" + std::to_string(background) + "m" + message + "\x1b[0m");

How to continue using -pedantic but ignore the warning for this particular function?

I am trying to use gcc Diagnostic Pragmas to ignore this escape sequence warning. I wrapped the function as follows, but it still raises a warning.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-pedantic"
std::string colorize_forground(std::string const& message, int const& background) {
    return std::string("\e[38;5;" + std::to_string(background) + "m" + message + "\x1b[0m");
}
#pragma GCC diagnostic pop
+4
1

:

https://gcc.gnu.org/onlinedocs/gcc-4.4.6/gcc/Warning-Options.html

gcc . , -Wno, , , .

-pedantic, ?

-pedandic , . , -pedantic-errors, , . , , .

, : -Wno-pedantic-ms-format ( MinGW)

0

All Articles