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})
systemfunction is declared in GCC with thewarn_unused_resultattribute indicates that the authors of the library consider the opposite: they consider that it is for thesystemfunction that a warning should be issued about the result ignored. C compilers usually do not issue such warnings unless it is explicitly requested. Thesystemfunction is just such a case. If you really do not want to check the result of thesystem, 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. - AnTset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")toset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wno-unused-result")gives the same error? - Adokenai