summaryrefslogtreecommitdiffstats
path: root/lib/AST/Type.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-10-01 02:31:28 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-10-01 02:31:28 +0000
commit9f569cca2a4c5fb6026005434e27025b9e71309d (patch)
tree4623644f5d65a1ca5526ea45bb24069efa896bfa /lib/AST/Type.cpp
parent00ca8483cf8e86a5ea08310c6727fd7848980043 (diff)
constexpr: semantic checking for constexpr functions and constructors. Based in
part on patches by Peter Collingbourne. We diverge from the C++11 standard in a few areas, mostly related to checking constexpr function declarations, and not just definitions. See WG21 paper N3308=11-0078 for details. Function invocation substitution is not available in this patch; constexpr functions cannot yet be used from within constant expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140926 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r--lib/AST/Type.cpp34
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 7471a3da5d..a2c6954d75 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -1134,29 +1134,19 @@ bool Type::isLiteralType() const {
return true;
// -- a class type that has all of the following properties:
if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
+ // -- a trivial destructor,
+ // -- every constructor call and full-expression in the
+ // brace-or-equal-initializers for non-static data members (if any)
+ // is a constant expression,
+ // -- it is an aggregate type or has at least one constexpr
+ // constructor or constructor template that is not a copy or move
+ // constructor, and
+ // -- all non-static data members and base classes of literal types
+ //
+ // We resolve DR1361 by ignoring the second bullet.
if (const CXXRecordDecl *ClassDecl =
- dyn_cast<CXXRecordDecl>(RT->getDecl())) {
- // -- a trivial destructor,
- if (!ClassDecl->hasTrivialDestructor())
- return false;
-
- // -- every constructor call and full-expression in the
- // brace-or-equal-initializers for non-static data members (if any)
- // is a constant expression,
- // We deliberately do not implement this restriction. It isn't necessary
- // and doesn't make any sense.
-
- // -- it is an aggregate type or has at least one constexpr
- // constructor or constructor template that is not a copy or move
- // constructor, and
- if (!ClassDecl->isAggregate() &&
- !ClassDecl->hasConstexprNonCopyMoveConstructor())
- return false;
-
- // -- all non-static data members and base classes of literal types
- if (ClassDecl->hasNonLiteralTypeFieldsOrBases())
- return false;
- }
+ dyn_cast<CXXRecordDecl>(RT->getDecl()))
+ return ClassDecl->isLiteral();
return true;
}