public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17037] New: static map in template crash on runtime when inserting
@ 2004-08-15 19:02 florent dot gallet at orange dot fr
2004-08-15 19:59 ` [Bug c++/17037] " bangerth at dealii dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: florent dot gallet at orange dot fr @ 2004-08-15 19:02 UTC (permalink / raw)
To: gcc-bugs
I use the mingw version of g++ 3.4.1 on windowsXP
Maybe my code is wrong but g++ should have say it before compiling and linking.
Don't know if this bug is on other version.
Here is how to reproduce the bug :
#include <iostream>
#include <map>
using namespace std;
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
template <typename _dxty>
class f
{
public:
typedef map<const _dxty*, int, ltstr > mapType;
protected:
static mapType months;
public:
f()
{
cout << "beginning" << endl;
months["toto"] = 1;
cout << "crash when inserting, same thing with insert" << endl;
}
};
// this is maybe wrong but it compile and link this way
template class f<char>;
template <> f<char>::mapType f<char>::months;
int main()
{
f<char> a;
cin.get();
return 0;
}
--
Summary: static map in template crash on runtime when inserting
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: critical
Priority: P1
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: florent dot gallet at orange dot fr
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/17037] static map in template crash on runtime when inserting
2004-08-15 19:02 [Bug c++/17037] New: static map in template crash on runtime when inserting florent dot gallet at orange dot fr
@ 2004-08-15 19:59 ` bangerth at dealii dot org
2004-08-15 21:41 ` florent dot gallet at orange dot fr
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-08-15 19:59 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-08-15 19:59 -------
The code is invalid in a number of ways about which the compiler
can't do much. First, with this line:
template <> f<char>::mapType f<char>::months;
This declares the _existence_ of a specialization. It does not
_define_ it.
The second bug is that you declare the specialization _after_ explicit
instantiation of the class. The standard doesn't allow it. Since you
do so, the compiler also can't warn you that that symbol doesn't exist,
since it already instantiated it.
For both these cases, no diagnostics are required.
If you fix your code, the program runs just fine.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/17037] static map in template crash on runtime when inserting
2004-08-15 19:02 [Bug c++/17037] New: static map in template crash on runtime when inserting florent dot gallet at orange dot fr
2004-08-15 19:59 ` [Bug c++/17037] " bangerth at dealii dot org
@ 2004-08-15 21:41 ` florent dot gallet at orange dot fr
2004-08-15 22:52 ` bangerth at dealii dot org
2004-08-15 23:26 ` florent dot gallet at orange dot fr
3 siblings, 0 replies; 5+ messages in thread
From: florent dot gallet at orange dot fr @ 2004-08-15 21:41 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From florent dot gallet at orange dot fr 2004-08-15 21:41 -------
Sorry if my code is wrong, I was trying to convert old code, but I really
don't see where's the prob :(
2 things :
- first: sorry for "template class f<char>;" it was in the other code (forgot
to remove it to make this small piece of code)
- second: before I've tryed :
template f<char>::mapType f<char>::months;
or even
template class f<char>::mapType f<char>::months;
// error: explicit instantiation of `f<char>::months' but no definition
available
and
template f<char>::mapType f<char>::months;
template <> f<char>::mapType f<char>::months;
or
template <> f<char>::mapType f<char>::months;
template f<char>::mapType f<char>::months;
but it crash the same way so I've removed it to make a smaller code
If you know how to do I'd really like to know because I'm becoming a little
confused with the new syntax :S
And thanks to help me :)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/17037] static map in template crash on runtime when inserting
2004-08-15 19:02 [Bug c++/17037] New: static map in template crash on runtime when inserting florent dot gallet at orange dot fr
2004-08-15 19:59 ` [Bug c++/17037] " bangerth at dealii dot org
2004-08-15 21:41 ` florent dot gallet at orange dot fr
@ 2004-08-15 22:52 ` bangerth at dealii dot org
2004-08-15 23:26 ` florent dot gallet at orange dot fr
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-08-15 22:52 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-08-15 22:52 -------
This is the syntax to use:
template <typename T> typename f<T>::mapType f<T>::months;
template class f<char>;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/17037] static map in template crash on runtime when inserting
2004-08-15 19:02 [Bug c++/17037] New: static map in template crash on runtime when inserting florent dot gallet at orange dot fr
` (2 preceding siblings ...)
2004-08-15 22:52 ` bangerth at dealii dot org
@ 2004-08-15 23:26 ` florent dot gallet at orange dot fr
3 siblings, 0 replies; 5+ messages in thread
From: florent dot gallet at orange dot fr @ 2004-08-15 23:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From florent dot gallet at orange dot fr 2004-08-15 23:26 -------
It works :)
(I'll test in my project)
Sorry to have bothered you, I really thought, it could be a bug :S
Thanks again
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17037
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-08-15 23:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-15 19:02 [Bug c++/17037] New: static map in template crash on runtime when inserting florent dot gallet at orange dot fr
2004-08-15 19:59 ` [Bug c++/17037] " bangerth at dealii dot org
2004-08-15 21:41 ` florent dot gallet at orange dot fr
2004-08-15 22:52 ` bangerth at dealii dot org
2004-08-15 23:26 ` florent dot gallet at orange dot fr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).