summaryrefslogtreecommitdiffstats
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-03-02 04:14:40 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-03-02 04:14:40 +0000
commit16581335fc32abcbc6ab14eda7af38cf759664b7 (patch)
treeee8e69c07d34c7c01643e5cdbd2be42e7aed780c /lib/AST/Decl.cpp
parent0524171a57e6f9f6ee79c02ed4e20c5914d8b2db (diff)
Ensure that we instantiate static reference data members of class templates
early, since their values can be used in constant expressions in C++11. For odr-use checking, the opposite change is required, since references are odr-used whether or not they satisfy the requirements for appearing in a constant expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151881 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index bd7579996f..03b2794c0e 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -1372,11 +1372,18 @@ void VarDecl::setInit(Expr *I) {
bool VarDecl::isUsableInConstantExpressions() const {
const LangOptions &Lang = getASTContext().getLangOptions();
- // Only const variables can be used in constant expressions in C++. C++98 does
+ if (!Lang.CPlusPlus)
+ return false;
+
+ // In C++11, any variable of reference type can be used in a constant
+ // expression if it is initialized by a constant expression.
+ if (Lang.CPlusPlus0x && getType()->isReferenceType())
+ return true;
+
+ // Only const objects 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())
+ if (!getType().isConstQualified() || getType().isVolatileQualified())
return false;
// In C++, const, non-volatile variables of integral or enumeration types
@@ -1384,9 +1391,9 @@ bool VarDecl::isUsableInConstantExpressions() const {
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());
+ // Additionally, in C++11, non-volatile constexpr variables can be used in
+ // constant expressions.
+ return Lang.CPlusPlus0x && isConstexpr();
}
/// Convert the initializer for this declaration to the elaborated EvaluatedStmt