First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 17445
Product:  
Component:  
Status: RESOLVED
Resolution: INVALID
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: carlson14@llnl.gov
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 17445 depends on: Show dependency tree
Show dependency graph
Bug 17445 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2004-09-13 00:39
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 From Andrew Pinski 2004-09-13 01:03 -------
*** Bug 17446 has been marked as a duplicate of this bug. ***

------- Comment #2 From Andrew Pinski 2004-09-13 01:03 -------
You want:
template<>
MyType<Sample> list;
char *MyType<Sample>::name = "Hello\n";

------- Comment #3 From Leslie Barnes 2005-04-18 06:38 -------
(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 From Giovanni Bajo 2005-04-18 09:08 -------
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 From Leslie Barnes 2005-04-18 13:37 -------
(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 From Wolfgang Bangerth 2005-04-18 20:16 -------
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 From Leslie Barnes 2005-04-19 00:02 -------
(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 From Wolfgang Bangerth 2005-04-19 14:08 -------
Why? This code as always wrong. It has nothing to do with gcc3.4.x. 
W. 

------- Comment #9 From Andrew Pinski 2005-04-25 04:09 -------
*** Bug 21200 has been marked as a duplicate of this bug. ***

------- Comment #10 From Andrew Pinski 2005-04-25 04:11 -------
*** Bug 11585 has been marked as a duplicate of this bug. ***

------- Comment #11 From Andrew Pinski 2005-04-25 04:12 -------
*** Bug 14891 has been marked as a duplicate of this bug. ***

------- Comment #12 From Andrew Pinski 2005-04-25 04:12 -------
*** Bug 11930 has been marked as a duplicate of this bug. ***

------- Comment #13 From Wallace Owen 2005-07-28 18:47 -------
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 From Wolfgang Bangerth 2005-07-28 19:43 -------
I believe you can't. 

First Last Prev Next    No search results available      Search page      Enter new bug