}
/// \brief Determine whether this function should be inlined, because it is
- /// either marked "inline" or is a member function of a C++ class that
- /// was defined in the class body.
+ /// either marked "inline" or "constexpr" or is a member function of a class
+ /// that was defined in the class body.
bool isInlined() const;
bool isInlineDefinitionExternallyVisible() const;
"the parameter for this explicitly-defaulted copy assignment operator is "
"const, but a member or base requires it to be non-const">;
def err_defaulted_copy_assign_quals : Error<
- "an explicitly-defaulted copy assignment operator may not have 'const' "
- "or 'volatile' qualifiers">;
+ "an explicitly-defaulted copy assignment operator may not have 'const', "
+ "'constexpr' or 'volatile' qualifiers">;
def err_defaulted_move_ctor_params : Error<
"an explicitly-defaulted move constructor must have exactly one parameter">;
def err_defaulted_move_ctor_volatile_param : Error<
"the parameter for an explicitly-defaulted move assignment operator may not "
"be const">;
def err_defaulted_move_assign_quals : Error<
- "an explicitly-defaulted move assignment operator may not have 'const' "
- "or 'volatile' qualifiers">;
+ "an explicitly-defaulted move assignment operator may not have 'const', "
+ "'constexpr' or 'volatile' qualifiers">;
def err_incorrect_defaulted_exception_spec : Error<
"exception specification of explicitly defaulted %select{default constructor|"
"copy constructor|move constructor|copy assignment operator|move assignment "
FreeFunction = (DC && !DC->isRecord());
}
+ // C++0x [dcl.constexpr]p8: A constexpr specifier for a non-static member
+ // function that is not a constructor declares that function to be const.
+ if (D.getDeclSpec().isConstexprSpecified() && !FreeFunction &&
+ D.getName().getKind() != UnqualifiedId::IK_ConstructorName &&
+ D.getName().getKind() != UnqualifiedId::IK_ConstructorTemplateId &&
+ !(FnTy->getTypeQuals() & DeclSpec::TQ_const)) {
+ // Rebuild function type adding a 'const' qualifier.
+ FunctionProtoType::ExtProtoInfo EPI = FnTy->getExtProtoInfo();
+ EPI.TypeQuals |= DeclSpec::TQ_const;
+ T = Context.getFunctionType(FnTy->getResultType(),
+ FnTy->arg_type_begin(),
+ FnTy->getNumArgs(), EPI);
+ }
+
// C++0x [dcl.fct]p6:
// A ref-qualifier shall only be part of the function type for a
// non-static member function, the function type to which a pointer to
// constexpr functions and constexpr constructors are implicitly inline.
struct S {
constexpr S(int n);
+ constexpr int g();
int n;
};
return s.n * 2;
}
+constexpr int S::g() {
+ return f(*this).n;
+}
+
// CHECK: define linkonce_odr {{.*}} @_Z1f1S(
// CHECK: define linkonce_odr {{.*}} @_ZN1SC1Ei(
+// CHECK: define linkonce_odr {{.*}} @_ZNK1S1gEv(
int g() {
- return f(42).n;
+ return f(42).g();
}
};
struct ConstAssignment {
- ConstAssignment& operator=(ConstAssignment&&) const = default; // expected-error {{an explicitly-defaulted move assignment operator may not have 'const' or 'volatile' qualifiers}}
+ ConstAssignment& operator=(ConstAssignment&&) const = default; // expected-error {{an explicitly-defaulted move assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}}
};
}
};
struct ConstAssignment {
- ConstAssignment& operator=(const ConstAssignment&) const = default; // expected-error {{an explicitly-defaulted copy assignment operator may not have 'const' or 'volatile' qualifiers}}
+ ConstAssignment& operator=(const ConstAssignment&) const = default; // expected-error {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}}
};
}
bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}}
bad_decls&& operator = (bad_decls) = default; // expected-error 2{{lvalue reference}}
bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}}
- bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const' or 'volatile' qualifiers}}
+ bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const', 'constexpr' or 'volatile' qualifiers}}
};
struct A {}; struct B {};