Move most of the checking from ActOnCXXMemberDeclarator to other, more general routines. This is a step toward separating the checking logic from Declarators, which in turn is required for template instantiation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66734 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 0ea501d..daaedae 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -588,72 +588,8 @@
assert((Name || isInstField) && "No identifier for non-field ?");
- if (DS.isVirtualSpecified()) {
- if (!isFunc || DS.getStorageClassSpec() == DeclSpec::SCS_static) {
- Diag(DS.getVirtualSpecLoc(), diag::err_virtual_non_function);
- Member->setInvalidDecl();
- } else {
- cast<CXXMethodDecl>(Member)->setVirtual();
- CXXRecordDecl *CurClass = cast<CXXRecordDecl>(CurContext);
- CurClass->setAggregate(false);
- CurClass->setPOD(false);
- CurClass->setPolymorphic(true);
- }
- }
-
- // FIXME: The above definition of virtual is not sufficient. A function is
- // also virtual if it overrides an already virtual function. This is important
- // to do here because it decides the validity of a pure specifier.
-
- if (Init) {
- // C++ 9.2p4: A member-declarator can contain a constant-initializer only
- // if it declares a static member of const integral or const enumeration
- // type.
- if (VarDecl *CVD = dyn_cast<VarDecl>(Member)) {
- // ...static member of...
- CVD->setInit(Init);
- // ...const integral or const enumeration type.
- if (Context.getCanonicalType(CVD->getType()).isConstQualified() &&
- CVD->getType()->isIntegralType()) {
- // constant-initializer
- if (CheckForConstantInitializer(Init, CVD->getType()))
- Member->setInvalidDecl();
-
- } else {
- // not const integral.
- Diag(Loc, diag::err_member_initialization)
- << Name << Init->getSourceRange();
- Member->setInvalidDecl();
- }
-
- } else {
- // not static member. perhaps virtual function?
- if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) {
- // With declarators parsed the way they are, the parser cannot
- // distinguish between a normal initializer and a pure-specifier.
- // Thus this grotesque test.
- IntegerLiteral *IL;
- if ((IL = dyn_cast<IntegerLiteral>(Init)) && IL->getValue() == 0 &&
- Context.getCanonicalType(IL->getType()) == Context.IntTy) {
- if (MD->isVirtual())
- MD->setPure();
- else {
- Diag(Loc, diag::err_non_virtual_pure)
- << Name << Init->getSourceRange();
- Member->setInvalidDecl();
- }
- } else {
- Diag(Loc, diag::err_member_function_initialization)
- << Name << Init->getSourceRange();
- Member->setInvalidDecl();
- }
- } else {
- Diag(Loc, diag::err_member_initialization)
- << Name << Init->getSourceRange();
- Member->setInvalidDecl();
- }
- }
- }
+ if (Init)
+ AddInitializerToDecl(Member, ExprArg(*this, Init), false);
if (isInstField) {
FieldCollector->Add(cast<FieldDecl>(Member));