我们有以下法典:
#if !defined(__cplusplus)
# error This file should be compiled as C++
#endif
#include <stdio.h>
#include <string>
//#define USE_CXX_CLASS
#ifdef USE_CXX_CLASS
class SomeClass
{
public:
SomeClass() {}
~SomeClass() {}
std::string GetSomeString()
{
// case #1
}
};
#endif // USE_CXX_CLASS
int foo()
{
// case #2
}
int
main (int argc, char *argv[])
{
(void)argc;
(void)argv;
#ifdef USE_CXX_CLASS
SomeClass someInstance;
someInstance.GetSomeString();
#endif // USE_CXX_CLASS
foo();
return 0;
}
并相信,将汇编C++编(而不是C组编)的版本4.2.1,其中可选择<代码>-Wreturn-type-Werror=return-type。 如果将上述代码汇编成册,则不必首先填写/#define USE_CXX_CLASS
。 页: 1
.../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
但是,如果<代码>/#define USE_CXX_CLASS行不通,则警告is。 a. 被视为错误:
.../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),另一个是C++职能(案例1)。 海事组织,这不应成为问题。 我希望这两种条件都被视为错误,我不想在此刻添加<代码>-Werror或-Wall
(或许会以后这样做),但这不属于这一问题的范围。
我的分点是:
- Is there some GCC switch that I am missing that should work? (No I do not want to use
#pragma
s.) - Is this a bug that has been addressed in a more recent version of GCC?
For reference, I have already poured through other similar questions already, including the following: