diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-04 09:53:13 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-04 09:53:13 +0000 |
commit | 282e7e66748cc6dd14d6f7f2cb52e5373c531e61 (patch) | |
tree | 65a943e4a9c8a0534b580dcbbbcb6791451b5a56 /lib/Sema/SemaStmt.cpp | |
parent | f39aec17b89f8f0dd78e78c50ad2fa08f12272e3 (diff) |
In C++11 mode, when an integral constant expression is desired and we have a
value of class type, look for a unique conversion operator converting to
integral or unscoped enumeration type and use that. Implements [expr.const]p5.
Sema::VerifyIntegerConstantExpression now performs the conversion and returns
the converted result. Some important callers of Expr::isIntegralConstantExpr
have been switched over to using it (including all of those required for C++11
conformance); this switch brings a side-benefit of improved diagnostics and, in
several cases, simpler code. However, some language extensions and attributes
have not been moved across and will not perform implicit conversions on
constant expressions of literal class type where an ICE is required.
In passing, fix static_assert to perform a contextual conversion to bool on its
argument.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 42b608e631..e49bcfada6 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -274,15 +274,17 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, if (!getLangOptions().CPlusPlus0x) { // C99 6.8.4.2p3: The expression shall be an integer constant. // However, GCC allows any evaluatable integer expression. - if (!LHSVal->isTypeDependent() && !LHSVal->isValueDependent() && - VerifyIntegerConstantExpression(LHSVal)) - return StmtError(); + if (!LHSVal->isTypeDependent() && !LHSVal->isValueDependent()) { + LHSVal = VerifyIntegerConstantExpression(LHSVal).take(); + if (!LHSVal) + return StmtError(); + } // GCC extension: The expression shall be an integer constant. - if (RHSVal && !RHSVal->isTypeDependent() && !RHSVal->isValueDependent() && - VerifyIntegerConstantExpression(RHSVal)) { - RHSVal = 0; // Recover by just forgetting about it. + if (RHSVal && !RHSVal->isTypeDependent() && !RHSVal->isValueDependent()) { + RHSVal = VerifyIntegerConstantExpression(RHSVal).take(); + // Recover from an error by just forgetting about it. } } |