Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

The behavior ICC triggers unused_function warning is odd

Xue__Liang
Beginner
1,080 Views

I'm using ICC Version 19.0.6 Build 20191202 to build on Ubuntu 18.04.1.  

I found that the warning [-Wunused_function] only take class into consideration, meaning if the member function of a class is never referenced, it trigger the warning, however while if a free function is never referenced, no such warning will be shown. I also try on GCC, which shows a opposite behavior.

For example, the following cpp codes will trigger no warning by ICC, but a warning [-Wunused_function] by GCC.

static void SFoo() { return;}

int main()
{
    return 0;
}

 

Is the behavior of ICC expected?  

 

0 Kudos
10 Replies
RahulV_intel
Moderator
1,080 Views

Hi,

Could you also specify your gcc version?

You are right, in case free function is not being referenced, "gcc" throws a warning, but "icc" doesn't. However, in case class member function is not being referenced, both icc and gcc are not throwing any warning. Tried with icc version 19.1 and gcc version 7.4.0 using "-Wall" flag.

-Rahul

 

 

 

0 Kudos
Xue__Liang
Beginner
1,080 Views

Hi Rahul,

The GCC version is: gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0

The result you see is the same regarding GCC behavior, but for ICC, your result differs from mine.

Mine result shows ICC throws warning for class, and only for class. 

My ICC Version  is 19.0.6 and yours is 19.1, maybe that's why the different behavior.

What's the expected behavior?  throw warning or not for class?

 

--Liang

 

0 Kudos
RahulV_intel
Moderator
1,080 Views

Hi Liang,

We are investigating this query with the Intel engineering team and we will get back to you at the earliest.

-Rahul

0 Kudos
Viet_H_Intel
Moderator
1,080 Views

I don't have the exact icc/gcc versions which you have. But I don't see any differences with icc 19.0.5, 9.1.0, gcc7.3.0 and 8.1.0

$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.5.281 Build 20190815
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

$ icc t.c -c -Wunused-function
t.c(1): warning #177: function "SFoo" was declared but never referenced
  static void SFoo() { return;}
              ^

$ gcc t.c -c -Wunused-function
t.c:1:13: warning: ‘SFoo’ defined but not used [-Wunused-function]
 static void SFoo() { return;}
             ^~~~
$ icpc t.cpp -c -Wunused-function
t.cpp(1): warning #177: function "SFoo" was declared but never referenced
  static void SFoo() { return;}
              ^

$ g++ t.cpp -c -Wunused-function
t.cpp:1:13: warning: ‘void SFoo()’ defined but not used [-Wunused-function]
 static void SFoo() { return;}
             ^~~~
$ g++ t.cpp -c
$ icpc t.cpp -c
$ gcc t.c -c
$ icc t.c -c
$ cat t.c
static void SFoo() { return;}

int main()
{
    return 0;
}

$ cat t.cpp
static void SFoo() { return;}

int main()
{
    return 0;
}

How do I reproduce the differences?

0 Kudos
Xue__Liang
Beginner
1,080 Views

Hi Viet,

My ICC version is Version 19.0.6 Build 20191202, different from yours. It could be the reason why you cannot reproduce the issue.

--Liang

0 Kudos
Viet_H_Intel
Moderator
1,080 Views

Can you add -ww177 to your command line to see if the compiler emits the warning?

0 Kudos
Xue__Liang
Beginner
1,080 Views

Hi Viet

After experiment, the behavior is

icc -ww177:  both free function and class member function can emit warning#177

icc -Wall:       only class member function can emit warning#177

Does the behavior expected?

--Liang

0 Kudos
Viet_H_Intel
Moderator
1,080 Views

It isn't expected, but you can use -ww177 as a workaround. And the latest compiler emits the correct warning to.

0 Kudos
Viet_H_Intel
Moderator
901 Views

Let us know if this is still an issue. Otherwise, we will close it.


Thanks,


0 Kudos
Viet_H_Intel
Moderator
888 Views

We will no longer respond to this thread.  

If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.

Thanks,


0 Kudos
Reply