Bug 17445 - too few template-parameter-lists
Summary: too few template-parameter-lists
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.1
: P1 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 11585 11930 14891 17446 21200 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-13 00:39 UTC by carlson14
Modified: 2005-07-28 19:43 UTC (History)
5 users (show)

See Also:
Host: alphaev67-dec-osf5.1
Target: alphaev67-dec-osf5.1
Build: alphaev67-dec-osf5.1
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description carlson14 2004-09-13 00:39:33 UTC
The following code give this error (compiles fine in 3.3.3):
I don't know if I need to fix my code, or if it is a bug
in 3.4.1.

test.cpp:10: error: too few template-parameter-lists
test.cpp:10: error: expected `,' or `;' before '=' token

template <class T> class MyType {
public:
 static char *name;
};
 
class Sample {
};
 
MyType<Sample> list;
char *MyType<Sample>::name = "Hello\n";
 
 
int main(int argc, char **argv) {
}
gcc -v -save-temps test.cpp 
Reading specs 
from /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev67-
dec-osf5.1/3.4.1/specs
Configured with: /usr/global/src/gnu/gcc/gcc-3.4.1/configure --
prefix=/usr/local/tools/gnu/gcc/3.4.1_tru64_5
Thread model: posix
gcc version 3.4.1
 /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../libexec/gcc/alphaev67-
dec-osf5.1/3.4.1/cc1plus -E -quiet -v -
iprefix /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev67-
dec-osf5.1/3.4.1/ test.cpp -mcpu=ev67 -o test.ii
ignoring nonexistent 
directory "/usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev
67-dec-osf5.1/3.4.1/../../../../alphaev67-dec-osf5.1/include"
ignoring duplicate 
directory "/usr/local/tools/gnu/gcc/3.4.1_tru64_5/lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../include/c++/3.4.1"
ignoring duplicate 
directory "/usr/local/tools/gnu/gcc/3.4.1_tru64_5/lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../include/c++/3.4.1/alphaev67-dec-osf5.1"
ignoring duplicate 
directory "/usr/local/tools/gnu/gcc/3.4.1_tru64_5/lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../include/c++/3.4.1/backward"
ignoring duplicate 
directory "/usr/local/tools/gnu/gcc/3.4.1_tru64_5/lib/gcc/alphaev67-dec-
osf5.1/3.4.1/include"
ignoring nonexistent 
directory "/usr/local/tools/gnu/gcc/3.4.1_tru64_5/lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../alphaev67-dec-osf5.1/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../include/c++/3.4.1
 /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../include/c++/3.4.1/alphaev67-dec-osf5.1
 /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev67-dec-
osf5.1/3.4.1/../../../../include/c++/3.4.1/backward
 /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../lib/gcc/alphaev67-dec-
osf5.1/3.4.1/include
 /usr/local/include
 /usr/local/tools/gnu/gcc/3.4.1_tru64_5/include
 /usr/include
End of search list.
 /usr/local/tools/openSource/gcc/3.4.1_tru64_5/bin/../libexec/gcc/alphaev67-
dec-osf5.1/3.4.1/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cpp -
mcpu=ev67 -auxbase test -version -o test.s
GNU C++ version 3.4.1 (alphaev67-dec-osf5.1)
        compiled by GNU C version 3.3.3.
GGC heuristics: --param ggc-min-expand=57 --param ggc-min-heapsize=51200
Comment 1 Andrew Pinski 2004-09-13 01:03:17 UTC
*** Bug 17446 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Pinski 2004-09-13 01:03:49 UTC
You want:
template<>
MyType<Sample> list;
char *MyType<Sample>::name = "Hello\n";
Comment 3 Leslie Barnes 2005-04-18 06:38:23 UTC
(In reply to comment #2)
> You want:
> template<>
> MyType<Sample> list;
> char *MyType<Sample>::name = "Hello\n";

 The following code seg faults with g++ 3.4.3.  If I remove the "template <>",
it won't compile.  On g++ 3.3, without the "template <>" it is happy and prints
"goodbye".  With the "template <>" it also seg faults.

 I'd like to know if this is a bug, or my inability to figure out the correct
syntax.

 thanks


#include <cstdio>
#include <map>
template <class T> class MyType {
public:
    static std::map<char*,char*> m_map;
};
 
class Sample {
};
 
template class MyType<Sample>;
template <> std::map<char*,char*> MyType<Sample>::m_map;
 
int main(int argc, char **argv) {
    MyType<Sample>::m_map["hello"]="goodbye";
    printf("%s\n",MyType<Sample>::m_map["hello"]);
}
Comment 4 Giovanni Bajo 2005-04-18 09:08:04 UTC
A segfault in GCC is always a bug, even if the code is wrong. Would you please 
open a new bugreport about it?
Comment 5 Leslie Barnes 2005-04-18 13:37:09 UTC
(In reply to comment #4)
> A segfault in GCC is always a bug, even if the code is wrong. Would you please 
> open a new bugreport about it?

 Sorry, I wasn't clear.  The binary seg faults, not the compiler.
Comment 6 Wolfgang Bangerth 2005-04-18 20:16:12 UTC
This code has at least two bugs: 
 
template class MyType<Sample>; 
template <> std::map<char*,char*> MyType<Sample>::m_map; 
 
First, the instantiation must come *after* the definition of the static 
member. 
Second, the definition you thought you have written is in fact only the  
declaration of an explicit specialization of that member. It needs an 
initializer. You need to write 
 
template <> std::map<char*,char*> MyType<Sample>::m_map 
   = std::map<char*,char*>(); 
 
W. 
 
Comment 7 Leslie Barnes 2005-04-19 00:02:02 UTC
(In reply to comment #6)
> This code has at least two bugs: 
>  
> template class MyType<Sample>; 
> template <> std::map<char*,char*> MyType<Sample>::m_map; 
>  
> First, the instantiation must come *after* the definition of the static 
> member. 
> Second, the definition you thought you have written is in fact only the  
> declaration of an explicit specialization of that member. It needs an 
> initializer. You need to write 
>  
> template <> std::map<char*,char*> MyType<Sample>::m_map 
>    = std::map<char*,char*>(); 
>  
> W. 
>  

(In reply to comment #6)
> This code has at least two bugs: 
>  
> template class MyType<Sample>; 
> template <> std::map<char*,char*> MyType<Sample>::m_map; 
>  
> First, the instantiation must come *after* the definition of the static 
> member. 
> Second, the definition you thought you have written is in fact only the  
> declaration of an explicit specialization of that member. It needs an 
> initializer. You need to write 
>  
> template <> std::map<char*,char*> MyType<Sample>::m_map 
>    = std::map<char*,char*>(); 
>  
> W. 
>  

Great, thanks!  If someone could put this on the g++ 3.4.3 changes page, that
would probably save people quite a bit of time.

http://www.gnu.org/software/gcc/gcc-3.4/changes.html
Comment 8 Wolfgang Bangerth 2005-04-19 14:08:35 UTC
Why? This code as always wrong. It has nothing to do with gcc3.4.x. 
W. 
Comment 9 Andrew Pinski 2005-04-25 04:09:52 UTC
*** Bug 21200 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2005-04-25 04:11:17 UTC
*** Bug 11585 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2005-04-25 04:12:30 UTC
*** Bug 14891 has been marked as a duplicate of this bug. ***
Comment 12 Andrew Pinski 2005-04-25 04:12:59 UTC
*** Bug 11930 has been marked as a duplicate of this bug. ***
Comment 13 Wallace Owen 2005-07-28 18:47:24 UTC
From Wolfgang Bangerth:

You need to write:

template <> std::map<char*,char*> MyType<Sample>::m_map 
   = std::map<char*,char*>();

My problem with this is that it requires that the static member support the copy
constructor.  In my case, the static member is something that cannot be copied,
so I put an explicit copy constructor into the private section of my template
class, which makes the above statement generate an error that the copy
constructor is private.  How do I instantiate this static member?  It's default
constructor does all the initialization I want, and I don't want that
initialization done twice.
Comment 14 Wolfgang Bangerth 2005-07-28 19:43:06 UTC
I believe you can't.