diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-21 02:55:12 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-21 02:55:12 +0000 |
commit | 1d238ea926bbdd04356ce475934fcd4cac654c4b (patch) | |
tree | 06e68608a02ef5c6e4bf42648bd8323e50bd8b5e /lib/AST/Decl.cpp | |
parent | 14b94366a829d2ed1b1b6d5cec1bb83aad9aeca2 (diff) |
C++11 half of r147023: In C++11, additionally eagerly instantiate:
- constexpr function template instantiations
- variables of reference type
- constexpr variables
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147031 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 9028a09bc3..84a2a59ee2 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1339,6 +1339,26 @@ void VarDecl::setInit(Expr *I) { Init = I; } +bool VarDecl::isUsableInConstantExpressions() const { + const LangOptions &Lang = getASTContext().getLangOptions(); + + // Only const variables can be used in constant expressions in C++. C++98 does + // not require the variable to be non-volatile, but we consider this to be a + // defect. + if (!Lang.CPlusPlus || + !getType().isConstQualified() || getType().isVolatileQualified()) + return false; + + // In C++, const, non-volatile variables of integral or enumeration types + // can be used in constant expressions. + if (getType()->isIntegralOrEnumerationType()) + return true; + + // Additionally, in C++11, non-volatile constexpr variables and references can + // be used in constant expressions. + return Lang.CPlusPlus0x && (isConstexpr() || getType()->isReferenceType()); +} + /// Convert the initializer for this declaration to the elaborated EvaluatedStmt /// form, which contains extra information on the evaluated value of the /// initializer. |