This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66344] New: non-static data member initializer in class template fails to compile
- From: "barry.revzin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 30 May 2015 16:00:38 +0000
- Subject: [Bug c++/66344] New: non-static data member initializer in class template fails to compile
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66344
Bug ID: 66344
Summary: non-static data member initializer in class template
fails to compile
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
The following code fails to compile on gcc 5.1:
#include <map>
template <typename T>
struct X {
std::map<int, T>* storage = new std::map<int, T>;
};
int main() {
X<int> x;
}
The compile output is listed at the end of this comment. If the type of storage
were instead std::vector<T>*, it would compile. If the type were set as a
typedef, as in:
using U = std::map<int, T>;
U* storage = new U;
That also compiles. All versions of this code compile on clang 3.6.0.
main.cpp:5:51: error: expected ';' at end of member declaration
std::map<int, T>* storage = new std::map<int, T>;
^
main.cpp:5:51: error: declaration of 'std::map<int, T> X<T>::T'
main.cpp:3:11: error: shadows template parm 'class T'
template <typename T>
^
main.cpp:5:52: error: expected unqualified-id before '>' token
std::map<int, T>* storage = new std::map<int, T>;
^
main.cpp:5:46: error: wrong number of template arguments (1, should be at least
2)
std::map<int, T>* storage = new std::map<int, T>;
^
In file included from /usr/local/include/c++/5.1.0/map:61:0,
from main.cpp:1:
/usr/local/include/c++/5.1.0/bits/stl_map.h:96:11: note: provided for
'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
class map