Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
7569 Discussions

icc fails to warn of shadowing variables

BradleyKuszmaul
Beginner
183 Views
Given a variable with global scope, icc doesn't complain when a local variable shadows it.

gcc correctly complains.

(This is true in icc 12.0.0)

$ icc -c foo3.c -Wshadow

$ gcc -c foo3.c -Wshadow

foo3.c: In function foo:

foo3.c:2: warning: declaration of a shadows a global declaration

foo3.c:1: warning: shadowed declaration is here

foo3.c:3: warning: declaration of b shadows a global declaration

foo3.c:1: warning: shadowed declaration is here

$ cat foo3.c

int a,b;

int foo (int a) {

int b=a;

return b;

}

0 Kudos
2 Replies
Lingfeng_C_Intel
Employee
183 Views
Thanks Bradley,
I can reprodcue this case here, and I will submit this issue to our engineering team to investigate it more.

Thanks,
Wise
Shenghong_G_Intel
183 Views

FYI...This issue had been fixed in compiler v14.0 and latest v15.0, see below:

# cat temp.cpp
int a,b;

int foo (int a) {

int b=a;

return b;

}
# source /opt/intel/composer_xe_2013.1.117/bin/compilervars.sh intel64
# icc -v
icc version 13.0.1 (gcc version 4.7.0 compatibility)
# icc -c temp.cpp -Wshadow
# source /opt/intel/composer_xe_2013_sp1.1.106/bin/compilervars.sh intel64
# icc -v
icc version 14.0.1 (gcc version 4.8.0 compatibility)
# icc -c temp.cpp -Wshadow
temp.cpp(3): warning #3280: declaration hides variable "a" (declared at line 1)
  int foo (int a) {
               ^

temp.cpp(5): warning #3280: declaration hides variable "b" (declared at line 1)
  int b=a;
      ^

# source /opt/intel/composer_xe_2015.1.133/bin/compilervars.sh intel64
# icc -v
icc version 15.0.1 (gcc version 4.8.1 compatibility)
# icc -c temp.cpp -Wshadow
temp.cpp(3): warning #3280: declaration hides variable "a" (declared at line 1)
  int foo (int a) {
               ^

temp.cpp(5): warning #3280: declaration hides variable "b" (declared at line 1)
  int b=a;
      ^

#

 

Reply