Unnecessary warnings

Unnecessary warnings

Hello,

Compiling the following piece of code produces unnecessary warnings (warning #175: subscript out of range) with icpc version 13.0.0 (gcc version 4.6.3 compatibility), could you please tell me why ? Template parameters are evaluated at compile time before code generation right ?

template<int T> void fun() {
    int foo[2 + (T == 0)];
    if(T == 0)
        foo[2] = 2;
    else
        foo[1] = 2;
}
int main()
{
    fun<2>();
    fun<0>();
}

6 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Georg Zitzlsberger (Intel)的头像

Hello,

that's a bug for which I filed a defect (DPD200239677). This warning should not occur at all. I'll let you know once we fixed this issue.

Thank you for finding this!

Best regards,

Georg Zitzlsberger

Georg Zitzlsberger (Intel)的头像

Hello,

I need to correct my initial assumption: It's not a bug but a missing feature in our compiler front-end. Detecting evaluations of conditions requires additional logic that we don't have (yet). Unfortunately it's not easy to implement and is not planned.

Other compilers are known to not detect potential problems like that at all. So, we could regard this as an additional benefit to warn about such potential problems, even though we're overly sensitive.

Best regards,

Georg Zitzlsberger

引文:

Georg Zitzlsberger (Intel) 写道:

Other compilers are known to not detect potential problems like that at all. So, we could regard this as an additional benefit to warn about such potential problems, even though we're overly sensitive.


GCC doesn't detect such potential problems indeed, however clang (3.0 or newer) does it, and better than icc (no warning at all with -Warray-bounds, which is the expected behavior).

Hi everybody,

I detected that problem in June 2012 and it was in my 'List of issues / problems' with a lowest priority ( I'm sorry about this ). It is good to know that Georg confirmed that this is due to some issues with the compiler. I gave the lowest priority because I didn't consider it as a problem with the Intel C++ compiler ( 12.1.3.300 ) or with a piece of my codes.

So, here are some technical details:

[ Warning #175: Subscript out of range ]

------ Build started: Project: IccTestApp, Configuration: Debug Win32 ------
Compiling with Intel(R) C++ Compiler XE 12.1.3.300 [IA-32]... (Intel C++ Environment)
Stdphf.cpp
...
..\DataSet.h(194): warning #175: subscript out of range
if( g_uiVALUESETsizeof[ iDataType - _RTVALUESET_STARTINDEX ] == sizeof( T ) &&
^
detected during instantiation of "TDataSet< T, iDataType >::TDataSet() [with T=RTfloat={float}, iDataType=3]" at line 425 of "../TestSet.cpp"
...
Compiling with Intel(R) C++ Compiler XE 12.1.3.300 [IA-32]... (Intel C++ Environment)
IccTestApp.cpp
Compiling manifest to resources... (Microsoft VC++ Environment)
Linking... (Intel C++ Environment)
xilink: executing 'link'
Creating library ..\Debug\IccTestAppD.lib and object ..\Debug\IccTestAppD.exp
Embedding manifest... (Microsoft VC++ Environment)
IccTestApp - 0 error(s), 16 warning(s), 0 remark(s)

Best regards,
Sergey

>>...Detecting evaluations of conditions requires additional logic that we don't have (yet)...

In my case a variable 'iDataType' is evaluated at runtime and it is always greater than 0. So, if at compile time the compiler assumes a 0 value for the variable 'iDataType' than an expression ( iDataType - _RTVALUESET_STARTINDEX ) is less then 0 and there is a "false attempt" to access some memory outside of array 'g_uiVALUESETsizeof' and this is by design of that piece of code.

Once again, that is why I didn't consider it as an error.

登陆并发表评论。