-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstract Base By Reference Canidate Causing Errors #34
Comments
Does the problem persist if you replace all the |
The problem does not persist with #include <complex>
#include <iostream>
class AbstractBase
{
public:
virtual ~AbstractBase() {}
virtual int MethodToMakeBaseAbstract() const = 0;
};
class Derived : public AbstractBase
{
public:
int MethodToMakeBaseAbstract() const override { return 0; }
};
int FramesToSeconds( const AbstractBase& /*project*/ )
{
return 3;
}
int FramesToSeconds( std::complex<double> /*editRate*/ )
{
return 4;
}
int main()
{
AbstractBase* p = new Derived();
std::cout << FramesToSeconds( *p ) << std::endl;
delete p;
} |
Ok, this is what I think is happening here. |
If it helps the problem still persists if I adjust the int main()
{
AbstractBase* p = new Derived();
const AbstractBase& baseRef = *p;
std::cout << FramesToSeconds( baseRef ) << std::endl;
delete p;
} Maybe it is still fair to say But yes I think you are right about how it attempt to see if it can convert to a |
The changes in ff2530e cause The invalid instantiation happens outside the immediate context, and so is not just a substitution failure. A minimal reproducer that fails with GCC is:
The solution is use |
@mclow asked me to comment. See P0929, voted into the working paper as a defect report at Rapperswil 2018. The old rules for abstract classes don't work very well, because they create errors "too early", and in contexts where we never required the class type in question to even be a complete type. Under the new post-P0929 rules, I think boost's technique is valid. Declaring a function whose return type is an abstract class type is now valid, and it's only defining or calling such a function that renders the program ill-formed (and instantiating |
Thanks, @zygoloid -- this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86252 |
Please consider this sample code:
I believe the output should be
3
and with no problems compiling. It compiles fine on Clang. I am having issues with GCC (9.0.1.201902) and Microsoft Visual Studio 15.7.5 with Boost version 1.64.0 and higher (tested through Boost version 1.69.0). Boost version 1.63.0 seems builds fine with that example on GCC.Here is the compiler flags with using Wandbox to test this
Here are the errors I am seeing:
There are several workarounds I can do to get my code to compile such as make the
AbstractBase
class not be abstract (no pure virtual functions), or rename the function so it is no longer considered, and also make my function take the base class by pointer instead of reference. Because it builds on Clang, I am not sure if it is ultimately a GCC/MSVC bug.Let me know if there is any additional information I can give you to help. Thank you.
The text was updated successfully, but these errors were encountered: