Why is the error emitted twice?

Fully aware that the question I am asking is outside the purview of C ++ Standard, I am curious to know why GCC throws the same error twice? I know why there is an error, but I am looking forward to understand why duplication in the error message.

#include <iostream>
using namespace std;

struct A{
   virtual void f1() = 0;
};

struct B : A{
};

struct C : A{
   void f1(){}
};

struct D : C, B{
   void f2(){f1();}
};

int main(){}

Error:

prog.cpp: In member functionvoid D::f2()’:
prog.cpp:16: error: reference tof1is ambiguous
prog.cpp:5: error: candidates are: virtual void A::f1()
prog.cpp:12: error:                virtual void C::f1()
prog.cpp:16: error: reference tof1is ambiguous
prog.cpp:5: error: candidates are: virtual void A::f1()
prog.cpp:12: error:                virtual void C::f1()
+3
source share
3 answers

What version of g ++ are you using?

Interestingly, compiling the code that you show on MacOS X 10.6.4 using Apple g ++ 4.2.1, I get a double error message.

With my own build of g ++ 4.5.1, I get only one warning.

It seems that a bug has been fixed.

+2
source

:

#include <iostream>

using namespace std;

struct A{
   virtual void f1() = 0;
};

struct B : A{
};

struct C : A{
   void f1(){}
};



struct CPrime : A{
   void f1() {}
};

struct D : C, B, CPrime {
   void f2(){f1();}
};

int main(){ return 0; }

:

g++ prog.cpp
prog.cpp: In member functionvoid D::f2()’:
prog.cpp:20: error: reference tof1is ambiguous
prog.cpp:5: error: candidates are: virtual void A::f1()
prog.cpp:16: error:                 virtual void CPrime::f1()
prog.cpp:5: error:                 virtual void A::f1()
prog.cpp:12: error:                 virtual void C::f1()
prog.cpp:20: error: reference tof1is ambiguous
prog.cpp:5: error: candidates are: virtual void A::f1()
prog.cpp:16: error:                 virtual void CPrime::f1()
prog.cpp:5: error:                 virtual void A::f1()
prog.cpp:12: error:                 virtual void C::f1()
0

Source: https://habr.com/ru/post/1760675/


All Articles