Thank you for your report; I'd not seen that warning here, but no doubt I shall when I use that g++ version.
I can reassure you, and the compiler, that the warning is invalid. Both paths relay to a 'valid' IsValid() derived-class method, so there's no possibility of recursion.
Regards,
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The above code certainly does do infinite recursion.
The above code certainly does. However the amended version below doesn't, and that is a better match to the 4Pane code.
DataBase is intended as an abstract base class and objects of it are never created in 4Pane, so your line DataBase db1; never happens. Instead 4Pane uses the equivalent of
DataBase* db1 = new FakeFiledata;
So why not make DataBase abstract? Because it breaks compilation of a wxArray of them. Again, this is old code; nowadays I'd have used a vector instead.
Suggest try calling the routine and see what happens at run time.
Presumably because the compiler 'knows' that each DataBase pointer actually holds one of the derived classes, in reality DataBase::IsValid is not actually run.
which is why the clang compiler is getting upset. After this many years, however
broken the code may or not be, you clearly aren't that bothered about fixing it,
so it looks to me like continuing to find bugs in 4Pane is pointless, so I'll stop now
thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your report; I'd not seen that warning here, but no doubt I shall when I use that g++ version.
I can reassure you, and the compiler, that the warning is invalid. Both paths relay to a 'valid' IsValid() derived-class method, so there's no possibility of recursion.
Regards,
David
Warning produced by clang, a different C/C++ compiler.
Thanks for your re-assurance, but when the compiler and the developer are in disagreement, I tend to believe the compiler 99% of the time.
Suggest try calling the routine and see what happens at run time.
I can always file a bug report in clang, if needs be.
BTW it is known that clang's -Winfinite-recursion generates wrong warnings like https://llvm.org/bugs/show_bug.cgi?id=21294
I am not sure if the following code accurately summarises the code in question:
include <iostream></iostream>
using namespace std;
class DataBase
{
public:
virtual bool IsValid();
bool IsFake;
};
class FileData : public DataBase
{
public:
virtual bool IsValid()
{
cout << "in FileData " << endl;
return false;
}
};
class FakeFiledata : public DataBase
{
public:
FakeFiledata(){ IsFake = true; };
};
bool DataBase::IsValid()
{
if (IsFake)
return IsValid();
else
return IsValid();
}
int
main()
{
DataBase db1;
FileData fd1;
FakeFiledata ffd1;
}
The above code certainly does do infinite recursion.
The above code certainly does. However the amended version below doesn't, and that is a better match to the 4Pane code.
DataBase is intended as an abstract base class and objects of it are never created in 4Pane, so your line DataBase db1; never happens. Instead 4Pane uses the equivalent of
DataBase* db1 = new FakeFiledata;
So why not make DataBase abstract? Because it breaks compilation of a wxArray of them. Again, this is old code; nowadays I'd have used a vector instead.
Presumably because the compiler 'knows' that each DataBase pointer actually holds one of the derived classes, in reality DataBase::IsValid is not actually run.
It looks to me like your most recent code is irrelevant to the point I was trying to make.
My apologies for the confusion.
AFAIK, the casts in the original code don't affect anything. The code is
essentially
bool DataBase::IsValid()
{
if (something)
return IsValid();
else
return IsValid();
}
which is why the clang compiler is getting upset. After this many years, however
broken the code may or not be, you clearly aren't that bothered about fixing it,
so it looks to me like continuing to find bugs in 4Pane is pointless, so I'll stop now
thanks.