From 9f569cca2a4c5fb6026005434e27025b9e71309d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 1 Oct 2011 02:31:28 +0000 Subject: 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 --- lib/AST/Type.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'lib/AST/Type.cpp') 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()) { + // -- 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(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(RT->getDecl())) + return ClassDecl->isLiteral(); return true; } -- cgit v1.2.3-18-g5258