Bug 27070 - Different partial template specialization result with different optimization options?
Summary: Different partial template specialization result with different optimizatio...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-07 02:26 UTC by meter ten
Modified: 2006-04-07 02:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
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 meter ten 2006-04-07 02:26:45 UTC
gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu3)

Different  partial template specialization result with different  optimization options?

1. right result without optimization 
$g++ -O0 -g3 -c test.cpp
$g++ -O0 -g3 -c a.cpp
$g++ -O0 -g3 -o test test.o a.o
$./test
DEFAULT
PARTIAL

2. wrong  result with  optimization 
$g++ -O2 -g0 -c test.cpp
$g++ -O2 -g0 -c a.cpp
$g++ -O2 -g0 -o test test.o a.o
$./test
DEFAULT
DEFAULT
????Bug???

3.if write three part in one file ,we get the right result
$g++ -O2 -g0 -o test2  test2
$./test2
DEFAULT
PARTIAL

$g++ -O0 -g3 -o test2  test2
$./test2
DEFAULT
PARTIAL
 



 

//************
//a.h
//************

#ifndef A_H
#define A_H

#include
using namespace std;
template
class A
{
public:
void echo() {cout << "ĬÈÏ" << endl;}
}
;
#endif

//************
//a.cpp
//************
#include "a.h"
template <>
void
A<0>::echo()
{
cout << "ÌØ»¯" << endl;
}

//************
//test.cpp
//************
#include "a.h"
int main( int argc, char *argv[] )
{
A<1>  DEFAULT;
A<0>  PARTICULAR;
DEFAULT.echo();
PARTICULAR.echo();

return EXIT_SUCCESS;
}

//************
//test2.cpp
//************

#include
using namespace std;
template
class A
{
public:
void echo() {cout << "ĬÈÏ" << endl;}
}
;
template <>
void
A<0>::echo()
{
cout << "ÌØ»¯" << endl;
}

int main( int argc, char *argv[] )
{
A<1> DEFAULT;
A<0> PARTICULAR;
DEFAULT.echo();
PARTICULAR.echo();

return EXIT_SUCCESS;
}
Comment 1 meter ten 2006-04-07 02:37:40 UTC
this is not a bug.