GCC允许隐式int到指针转换?

时间:2014-05-05 22:46:44

标签: c++ gcc

所以我错误地将一个int传递给一个函数参数,期望一个指向const对象的指针,我从GCC得到了这个警告:

jni/../../../Source/Controller/UserExperienceManager.cpp: In member function 'void CUserExperienceManager::SendUXPToPOS(Types::CString)':
jni/../../../Source/Controller/UserExperienceManager.cpp:243:78: warning: invalid conversion from 'int' to 'const WebService_POSAgent::CDataCheck*' [-fpermissive]
jni/../../../../../Core/WebServices/Services/POSAgent/POSAgent.h:80:18: warning:   initializing argument 2 of 'CEvent& WebService_POSAgent::CPOSAgent::AddUserExperienceID(Types::CString, const WebService_POSAgent::CDataCheck*, Types::CString)' [-fpermissive]

我试图创建一个可重现的样本,但我无法做到,我不能在这里分享太多的代码。我在MSVC9上编译了同样的东西,它给了我一个错误。我很震惊,我没有收到GCC的错误!谁知道为什么?以下是一些简单的片段:

功能声明(类成员函数):

CEvent& AddUserExperienceID(CString userExperienceId, CDataCheck const* check, CString requestId = REQUEST_ID);

功能调用站点:

int nCheckNum = /*some value*/;
CPOSAgent::Instance().AddUserExperienceID(m_UserExperienceId, nCheckNum);

1 个答案:

答案 0 :(得分:4)

您正在使用-fpermissive设置编译该代码,该代码会将错误降级为警告。

 -fpermissive
  Downgrade some diagnostics about nonconformant code from errors to warnings.
  Thus, using -fpermissive will allow some nonconforming code to compile.

What does the fpermissive flag do?