-
Notifications
You must be signed in to change notification settings - Fork 68
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
C++98 GCC 8 assignment does nothing #59
Comments
The problem goes away if I declare a copy assignment operator for tc_optional_base& operator=( tc_optional_base const& rhs )
{
m_initialized = rhs.m_initialized;
m_storage = rhs.m_storage;
return *this;
} |
Hmm, it also goes away if I make this: void assign ( tc_optional_base const& rhs )
{
//this->operator=(rhs);
*this = rhs;
} |
It looks like a GCC bug. MWE (fails on any struct dummy {} ;
template <typename T>
struct foo : dummy
{
foo() {}
foo(T v_) : v(v_) {}
void assign(foo const& rhs)
{
this->operator=(rhs); // the assignment does nothing
//(*this).operator=(rhs); // this one does nothing too
//*this = rhs; // this one works as expected
}
T v;
};
template <typename T>
struct bar : foo<T>
{
typedef foo<T> base;
bar() : base() {}
bar(T v) : base(v) {}
bar& operator=(bar const& rhs)
{
this->assign( static_cast<base const&>(rhs) ) ;
return *this ;
}
};
int main()
{
bar<int> a, b(123);
a.assign(b);
if (a.v != 123) throw "problem!";
} If you remove inheriting from |
GCC bug report https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87531 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GCC 8.1.0/8.2.0/9.0.0
g++ -std=c++98
fails,g++ -std=c++11
is fine.The problem is not presented on GCC 7.3.0.
MWE:
https://wandbox.org/permlink/UPpKB0gpchSAaW61
The text was updated successfully, but these errors were encountered: