Suppose we have the following code:
#if !defined(__cplusplus)
# error This file should be compiled as C++
#endif
#include <stdio.h>
#include <string>
#ifdef USE_CXX_CLASS
class SomeClass
{
public:
SomeClass() {}
~SomeClass() {}
std::string GetSomeString()
{
}
};
#endif
int foo()
{
}
int
main (int argc, char *argv[])
{
(void)argc;
(void)argv;
#ifdef USE_CXX_CLASS
SomeClass someInstance;
someInstance.GetSomeString();
#endif
foo();
return 0;
}
Suppose he was to compile a C ++ compiler (and not a C compiler) from GCC version 4.2.1 with parameters -Wreturn-type -Werror=return-type. If the above code is compiled, since it is not the first to uncomment the line //#define USE_CXX_CLASSabove, then you will see a warning , but without errors :
.../gcc-4.2.1/bin/g++ -g -fPIC -Wreturn-type -Werror=return-type test.cpp -c -o test.o
test.cpp: In function 'int foo()':
test.cpp:26: warning: control reaches end of non-void function
But if the line is //#define USE_CXX_CLASSuncommented, a warning treated as an error:
.../gcc-4.2.1/bin/g++ -g -fPIC -Wreturn-type -Werror=return-type test.cpp -c -o test.o
test.cpp: In member function 'std::string SomeClass::GetSomeString()':
test.cpp:18: error: no return statement in function returning non-void [-Wreturn-type]
gmake: *** [test.o] Error 1
, - , ( # 2), - ++ ( # 1). , . , , -Werror -Wall (, , ).
:
- - GCC, , ? (,
#pragma.) - , GCC?
, , :