diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-11-05 16:20:31 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-11-05 16:20:31 +0000 |
commit | 64bffa9a6f40e5a3d5556f994f09f7bf45eecd4c (patch) | |
tree | 1dadd5d78769ad7701edc4f614b9c34e6020da5d /lib/Sema/SemaDecl.cpp | |
parent | f03d7c7af2ca8555c513ba7667acffb667445ecd (diff) |
Keep track of whether a C++ class is an aggregate. Don't allow initialization of non-aggregates with initializer lists.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58757 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5dc571c0ee..c8c253a3fb 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -701,6 +701,23 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, Init->getSourceRange()); return CheckSingleInitializer(Init, DeclType); + } else if (getLangOptions().CPlusPlus) { + // C++ [dcl.init]p14: + // [...] If the class is an aggregate (8.5.1), and the initializer + // is a brace-enclosed list, see 8.5.1. + // + // Note: 8.5.1 is handled below; here, we diagnose the case where + // we have an initializer list and a destination type that is not + // an aggregate. + // FIXME: In C++0x, this is yet another form of initialization. + if (const RecordType *ClassRec = DeclType->getAsRecordType()) { + const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(ClassRec->getDecl()); + if (!ClassDecl->isAggregate()) + return Diag(InitLoc, + diag::err_init_non_aggr_init_list, + DeclType.getAsString(), + Init->getSourceRange()); + } } InitListChecker CheckInitList(this, InitList, DeclType); |