https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92986
Bug ID: 92986
Summary: ODR violation not detected
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: geeteshmore at gmail dot com
Target Milestone: ---
Hi,
I've a testcase where a class with same name is called in multiple files.
However, depending on the order of compile, output is different.
Compiler is unable to detect the One Defination Rule Violation here.
Testcase:
++File2.cpp
//file2.cpp
#include
using namespace std;
class Radiator
{
public:
string fileName()
{
return "File2.cpp";
}
};
void print()
{
Radiator rad;
cout<<" Calling Class Radiator from File: " << rad.fileName() << endl;
}
main.cpp++
// The main module
#include
using namespace std;
class Radiator
{
public:
string fileName()
{
return "Main.cpp";
}
};
void main_print()
{
Radiator rad;
cout<<" Calling Class Radiator from File: " << rad.fileName() << endl;
}
int main()
{
main_print();
return 0;
}
+
Now when i compile :
g++ -std=c++0x -g file2.cpp main.cpp
I get following Output, which is not what I expected:
Calling Class Radiator from File: File2.cpp
But when i compile :
g++ -std=c++0x -g main.cpp file2.cpp
I get following correct Outputd:
Calling Class Radiator from File: Main.cpp
I tried using "-Wodr" but still i got no warnings.