[PATCH] D16973: Fix ICE with constexpr and friend functions
Olivier Goffart via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 12 04:39:18 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL260675: Fix ICE with constexpr and friend functions (authored by ogoffart).
Changed prior to commit:
http://reviews.llvm.org/D16973?vs=47146&id=47791#toc
Repository:
rL LLVM
http://reviews.llvm.org/D16973
Files:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
Index: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2005,3 +2005,13 @@
constexpr int a = *f().p;
constexpr int b = *g().p;
}
+
+namespace IncompleteClass {
+ struct XX {
+ static constexpr int f(XX*) { return 1; } // expected-note {{here}}
+ friend constexpr int g(XX*) { return 2; } // expected-note {{here}}
+
+ static constexpr int i = f(static_cast<XX*>(nullptr)); // expected-error {{constexpr variable 'i' must be initialized by a constant expression}} expected-note {{undefined function 'f' cannot be used in a constant expression}}
+ static constexpr int j = g(static_cast<XX*>(nullptr)); // expected-error {{constexpr variable 'j' must be initialized by a constant expression}} expected-note {{undefined function 'g' cannot be used in a constant expression}}
+ };
+}
Index: cfe/trunk/lib/AST/ExprConstant.cpp
===================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -3736,7 +3736,8 @@
/// expression.
static bool CheckConstexprFunction(EvalInfo &Info, SourceLocation CallLoc,
const FunctionDecl *Declaration,
- const FunctionDecl *Definition) {
+ const FunctionDecl *Definition,
+ const Stmt *Body) {
// Potential constant expressions can contain calls to declared, but not yet
// defined, constexpr functions.
if (Info.checkingPotentialConstantExpression() && !Definition &&
@@ -3749,7 +3750,8 @@
return false;
// Can we evaluate this function call?
- if (Definition && Definition->isConstexpr() && !Definition->isInvalidDecl())
+ if (Definition && Definition->isConstexpr() &&
+ !Definition->isInvalidDecl() && Body)
return true;
if (Info.getLangOpts().CPlusPlus11) {
@@ -4275,7 +4277,7 @@
const FunctionDecl *Definition = nullptr;
Stmt *Body = FD->getBody(Definition);
- if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition) ||
+ if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body) ||
!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, Info,
Result, ResultSlot))
return false;
@@ -5483,9 +5485,9 @@
}
const FunctionDecl *Definition = nullptr;
- FD->getBody(Definition);
+ auto Body = FD->getBody(Definition);
- if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition))
+ if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body))
return false;
// Avoid materializing a temporary for an elidable copy/move constructor.
@@ -5971,9 +5973,9 @@
}
const FunctionDecl *Definition = nullptr;
- FD->getBody(Definition);
+ auto Body = FD->getBody(Definition);
- if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition))
+ if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body))
return false;
if (ZeroInit && !HadZeroInit) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16973.47791.patch
Type: text/x-patch
Size: 3225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160212/731d999e/attachment-0001.bin>
More information about the cfe-commits
mailing list