Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22048

How do I ignore a particular gcc warning that's [enabled by default]?

$
0
0

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

#include <iostream>#include <string>//returns a colored string for terminal output streamsstd::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 message:

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 do I continue using -pedantic, but ignore the warning for this particular function?

I've been trying to use gcc's Diagnostic Pragmas to ignore this escape sequence warning.I wrapped the function the following way, but it still elicits 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

Viewing all articles
Browse latest Browse all 22048

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>