- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; }; $
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I escalated this to engineering team (DPD200415971). Thank you for reporting it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page