Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikairoya/701702 to your computer and use it in GitHub Desktop.
Save kikairoya/701702 to your computer and use it in GitHub Desktop.
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -3226,6 +3226,22 @@ check_field_decls (tree t, tree *access_decls,
warning (OPT_Weffc__,
" but does not override %<operator=(const %T&)%>", t);
}
+ if (cxx_dialect >= cxx0x
+ && (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
+ || type_has_move_constructor (t) || type_has_move_assign (t))
+ && !(TYPE_HAS_COPY_CTOR (t) && TYPE_HAS_COPY_ASSIGN (t)
+ && type_has_move_constructor (t) && type_has_move_assign (t)))
+ {
+ warning (OPT_Wdeprecated, "%q#T has non-trivial destructor or move ctor/assign", t);
+ if (! TYPE_HAS_COPY_CTOR (t))
+ warning (OPT_Wdeprecated, " implicit definition of %<%T(const %T&)%> is deprecated.", t, t);
+ if (! TYPE_HAS_COPY_ASSIGN (t))
+ warning (OPT_Wdeprecated, " implicit definition of %<operator=(const %T&)%> is deprecated.", t);
+ if (! type_has_move_constructor (t))
+ warning (OPT_Wdeprecated, " implicit definition of %<%T(%T&&)%> is deprecated.", t, t);
+ if (! type_has_move_assign (t))
+ warning (OPT_Wdeprecated, " implicit definition of %<operator=(%T&&)%> is deprecated.", t);
+ }
/* If any of the fields couldn't be packed, unset TYPE_PACKED. */
if (cant_pack)
#include <iostream>
struct well {
well() { std::cout << this << " def ctor\n"; }
well(const well &) { std::cout << this << " copy ctor\n"; }
well &operator =(const well &) { std::cout << this << " copy assign\n"; return *this; }
well(well &&) { std::cout << this << " move ctor\n"; }
well &operator =(well &&) { std::cout << this << " move assign\n"; return *this; }
~well() { std::cout << this << " destructor\n"; }
};
struct bad {
well w;
~bad() { }
};
#include <utility>
using std::move;
int main() {
std::cout << "use 'struct well' directly\n";
{
well w1;
well w2(w1);
well w3(move(w1));
w1 = w2;
w2 = move(w3);
}
std::cout << "use 'struct well' via 'struct bad'\n";
{
bad b1;
bad b2(b1);
bad b3(move(b1));
b1 = b2;
b2 = move(b3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment