diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-11-02 12:00:36 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-11-02 12:00:36 +0000 |
commit | 9b1754d058407e8f013e830e601a398347914701 (patch) | |
tree | 2249f88e9bd25da2e3960ad89ef6e0e894faca82 /clang/lib/Sema/SemaDeclCXX.cpp | |
parent | 4589760efd438a703e75882ffc8b0a01a68342d4 (diff) | |
download | bcm5719-llvm-9b1754d058407e8f013e830e601a398347914701.tar.gz bcm5719-llvm-9b1754d058407e8f013e830e601a398347914701.zip |
Sema: Disallow inheriting from classes with flexible array members
Flexible array members inherently index off of the end of their parent
type.
We shouldn't allow this type to be used as a base, virtual or otherwise,
because indexing off the end may find us inside of another base or the
derived types members.
llvm-svn: 193923
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index dce0592592a..c8338353ea9 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1370,6 +1370,18 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, CXXRecordDecl *CXXBaseDecl = cast<CXXRecordDecl>(BaseDecl); assert(CXXBaseDecl && "Base type is not a C++ type"); + // A class which contains a flexible array member is not suitable for use as a + // base class: + // - If the layout determines that a base comes before another base, + // the flexible array member would index into the subsequent base. + // - If the layout determines that base comes before the derived class, + // the flexible array member would index into the derived class. + if (CXXBaseDecl->hasFlexibleArrayMember()) { + Diag(BaseLoc, diag::err_base_class_has_flexible_array_member) + << CXXBaseDecl->getDeclName(); + return 0; + } + // C++ [class]p3: // If a class is marked final and it appears as a base-type-specifier in // base-clause, the program is ill-formed. |