Good day!

I am developing a program in the CLion environment on the Ubuntu 12.04 platform.
CMake version: 3.6.3.
GDB version: 7.11.1.
When building a project, the compiler issues a warning:

warning: ignoring return value of int system (const char *) ', declared with attribute warn_unused_result

On the one hand, this is a useful warning in case the result of the function is not used anywhere, but not when this function is system () . Can you please tell me how to disable this warning, and is it possible to do this if I use the optimization parameter -O3?

Here is what's in the CMakeList.txt file:

cmake_minimum_required(VERSION 3.6) project(MyProj) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") set(SOURCE_FILES Main.cpp) set(HEADER_FILES Main.h) add_executable(MyProj ${SOURCE_FILES}) 
  • 3
    The fact that the system function is declared in GCC with the warn_unused_result attribute indicates that the authors of the library consider the opposite: they consider that it is for the system function that a warning should be issued about the result ignored. C compilers usually do not issue such warnings unless it is explicitly requested. The system function is just such a case. If you really do not want to check the result of the system , then I would advise you not to disable it globally, but simply explicitly in the code to bring the result of the call to type (void) - this will suppress the warning. - AnT
  • @AnT, thanks for the reply! Alternatively, I wrote a wrapper function for system (), now I get the error code inside it, and in all other places I call the wrapper. - neo
  • Changing set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") to set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wno-unused-result") gives the same error? - Adokenai

0