summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-12-21 02:55:12 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-12-21 02:55:12 +0000
commit242ad89a15d5466d166d47978bfff983d40ab511 (patch)
tree6dbdd5a89a0874ea2545ebb1c6d6089fbc5dfa49 /clang/lib/AST/Decl.cpp
parentb9ccd553fca066e8f5e1353e612ef91bb85d20d1 (diff)
downloadbcm5719-llvm-242ad89a15d5466d166d47978bfff983d40ab511.tar.gz
bcm5719-llvm-242ad89a15d5466d166d47978bfff983d40ab511.zip
C++11 half of r147023: In C++11, additionally eagerly instantiate:
- constexpr function template instantiations - variables of reference type - constexpr variables llvm-svn: 147031
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r--clang/lib/AST/Decl.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 9028a09bc39..84a2a59ee23 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud