[Bug c++/92986] New: ODR violation not detected

2019-12-18 Thread geeteshmore at gmail dot com
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.

[Bug c++/92986] ODR violation not detected

2019-12-18 Thread geeteshmore at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92986

--- Comment #2 from Geetesh More  ---
But compiler should be throwing some message/warning about declaration of same
class in multiple files. This is common scenario in cases where a class is
copied in multiple files.

[Bug c++/92986] ODR violation not detected

2019-12-18 Thread geeteshmore at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92986

--- Comment #4 from Geetesh More  ---
I tried with -flto, but I'm not seeing any warning messages:
g++ -std=c++0x -g -flto -Wodr main.cpp file2.cpp

Am I missing anything here?