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

icc 17.0.0 accepts illegal C++ code with shadowed template parameters

Zhendong_Su
Beginner
1,028 Views

Compiler version and platform: 

Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.0.098 Build 20160721

According to the C++ standard, it is illegal to have a declaration that shadows a template parameter. 

$ icc -c small.cpp
$ 
$ g++-6.2 -c small.cpp
small.cpp:3:7: error: declaration of ‘int A<T>::T’ shadows template parameter
   int T;
       ^
small.cpp:1:12: note: template parameter ‘T’ declared here
 template < int T > struct A
            ^~~
$ clang++-3.8 -c small.cpp
small.cpp:3:7: error: declaration of 'T' shadows template parameter
  int T;
      ^
small.cpp:1:16: note: template parameter is declared here
template < int T > struct A 
               ^
1 error generated.
$ 
$ cat small.cpp
template < int T > struct A 
{
  int T;
};
$ 

 

0 Kudos
2 Replies
Igor_V_Intel
Employee
1,028 Views

I escalated this to engineering team (DPD200415971). Thank you for reporting it.

 

0 Kudos
Igor_V_Intel
Employee
1,028 Views

Note that the compiler generates an error with -strict_ansi option:

> icc -c -strict_ansi bug.cpp
bug.cpp(4): error: template parameter "T" may not be redeclared in this scope
    int T;
        ^

compilation aborted for bug.cpp (code 2)

This code is not in accordance with C++11 standard since a template-parameter shall not be redeclared within its scope.
So, I'd expect an error from the compiler even with no -strict_ansi option.

0 Kudos
Reply