p2.cpp revision 74e611a5fd0b5977c664d13a07b625ae23527d0d
174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
374e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl// FIXME: test with non-std qualifiers
474e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
574e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redlnamespace move {
674e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct Const {
774e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Const(const Const&&) = default; // expected-error {{the parameter for an explicitly-defaulted move constructor may not be const}}
874e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Const& operator=(const Const&&) = default; // expected-error {{the parameter for an explicitly-defaulted move assignment operator may not be const}}
974e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
1074e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
1174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct Volatile {
1274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Volatile(volatile Volatile&&) = default; // expected-error {{the parameter for an explicitly-defaulted move constructor may not be volatile}}
1374e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Volatile& operator=(volatile Volatile&&) = default; // expected-error {{the parameter for an explicitly-defaulted move assignment operator may not be volatile}}
1474e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
1574e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
1674e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct AssignmentRet1 {
1774e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    AssignmentRet1&& operator=(AssignmentRet1&&) = default; // expected-error {{an explicitly-defaulted move assignment operator must return an unqualified lvalue reference to its class type}}
1874e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
1974e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
2074e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct AssignmentRet2 {
2174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    const AssignmentRet2& operator=(AssignmentRet2&&) = default; // expected-error {{an explicitly-defaulted move assignment operator must return an unqualified lvalue reference to its class type}}
2274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
2374e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
2474e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct ConstAssignment {
2574e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    ConstAssignment& operator=(ConstAssignment&&) const = default; // expected-error {{an explicitly-defaulted move assignment operator may not have 'const' or 'volatile' qualifiers}}
2674e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
2774e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl}
2874e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
2974e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redlnamespace copy {
3074e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct Volatile {
3174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Volatile(const volatile Volatile&) = default; // expected-error {{the parameter for an explicitly-defaulted copy constructor may not be volatile}}
3274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Volatile& operator=(const volatile Volatile&) = default; // expected-error {{the parameter for an explicitly-defaulted copy assignment operator may not be volatile}}
3374e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
3474e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
3574e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct Const {
3674e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Const(const Const&) = default;
3774e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    Const& operator=(const Const&) = default;
3874e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
3974e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
4074e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct NonConst {
4174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    NonConst(NonConst&) = default;
4274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    NonConst& operator=(NonConst&) = default;
4374e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
4474e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
4574e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct BadConst {
4674e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    NonConst nc; // makes implicit copy non-const
4774e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    BadConst(const BadConst&) = default; // expected-error {{is const, but}}
4874e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    BadConst& operator=(const BadConst&) = default; // expected-error {{is const, but}}
4974e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
5074e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
5174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct AssignmentRet1 {
5274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    AssignmentRet1&& operator=(const AssignmentRet1&) = default; // expected-error {{an explicitly-defaulted copy assignment operator must return an unqualified lvalue reference to its class type}}
5374e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
5474e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
5574e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct AssignmentRet2 {
5674e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    const AssignmentRet2& operator=(const AssignmentRet2&) = default; // expected-error {{an explicitly-defaulted copy assignment operator must return an unqualified lvalue reference to its class type}}
5774e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
5874e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl
5974e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  struct ConstAssignment {
6074e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl    ConstAssignment& operator=(const ConstAssignment&) const = default; // expected-error {{an explicitly-defaulted copy assignment operator may not have 'const' or 'volatile' qualifiers}}
6174e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl  };
6274e611a5fd0b5977c664d13a07b625ae23527d0dSebastian Redl}
63