diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-11-03 20:45:27 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-11-03 20:45:27 +0000 |
commit | 18fe56863be253a27b940022d27a3101778adaf6 (patch) | |
tree | b2cf207b1ee2380ade5236d92c0e9758090f2946 /lib/Sema/SemaDecl.cpp | |
parent | 4fd7ffe4c990357cec0c74f216cacc9825e46048 (diff) |
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
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 16053cecdb..a10470e0d4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1621,11 +1621,37 @@ void Sema::ActOnUninitializedDecl(DeclTy *dcl) { // 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 |