Implicit support for direct initialization of objects of class type, e.g.,
X x(5, 7);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 16053ce..a10470e 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1621,11 +1621,37 @@
// function return type, in the declaration of a class member
// within its class declaration (9.2), and where the extern
// specifier is explicitly used.
- if (Type->isReferenceType() && Var->getStorageClass() != VarDecl::Extern)
+ if (Type->isReferenceType() && Var->getStorageClass() != VarDecl::Extern) {
Diag(Var->getLocation(),
diag::err_reference_var_requires_init,
Var->getName(),
SourceRange(Var->getLocation(), Var->getLocation()));
+ Var->setInvalidDecl();
+ return;
+ }
+
+ // C++ [dcl.init]p9:
+ //
+ // If no initializer is specified for an object, and the object
+ // is of (possibly cv-qualified) non-POD class type (or array
+ // thereof), the object shall be default-initialized; if the
+ // object is of const-qualified type, the underlying class type
+ // shall have a user-declared default constructor.
+ if (getLangOptions().CPlusPlus) {
+ QualType InitType = Type;
+ if (const ArrayType *Array = Context.getAsArrayType(Type))
+ InitType = Array->getElementType();
+ if (InitType->isRecordType()) {
+ CXXConstructorDecl *Constructor
+ = PerformDirectInitForClassType(InitType, 0, 0, Var->getLocation(),
+ SourceRange(Var->getLocation(),
+ Var->getLocation()),
+ Var->getName(),
+ /*HasInitializer=*/false);
+ if (!Constructor)
+ Var->setInvalidDecl();
+ }
+ }
#if 0
// FIXME: Temporarily disabled because we are not properly parsing