r190722 - Part three of PR15721: if we have an invalid CXXDefaultInitExpr, don't crash if
Richard Smith
richard-llvm at metafoo.co.uk
Fri Sep 13 13:51:45 PDT 2013
Author: rsmith
Date: Fri Sep 13 15:51:45 2013
New Revision: 190722
URL: http://llvm.org/viewvc/llvm-project?rev=190722&view=rev
Log:
Part three of PR15721: if we have an invalid CXXDefaultInitExpr, don't crash if
we try to constant-evaluate it. Patch by Karthik Bhat, test by me.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=190722&r1=190721&r2=190722&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Sep 13 15:51:45 2013
@@ -3742,8 +3742,12 @@ public:
{ return StmtVisitorTy::Visit(E->getReplacement()); }
RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
{ return StmtVisitorTy::Visit(E->getExpr()); }
- RetTy VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
- { return StmtVisitorTy::Visit(E->getExpr()); }
+ RetTy VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E) {
+ // The initializer may not have been parsed yet, or might be erroneous.
+ if (!E->getExpr())
+ return Error(E);
+ return StmtVisitorTy::Visit(E->getExpr());
+ }
// We cannot create any objects for which cleanups are required, so there is
// nothing to do here; all cleanups must come from unevaluated subexpressions.
RetTy VisitExprWithCleanups(const ExprWithCleanups *E)
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=190722&r1=190721&r2=190722&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Fri Sep 13 15:51:45 2013
@@ -1776,3 +1776,21 @@ namespace ZeroSizeTypes {
return &arr[3] - &arr[0]; // expected-note {{subtraction of pointers to type 'int [0]' of zero size}}
}
}
+
+namespace BadDefaultInit {
+ template<int N> struct X { static const int n = N; };
+
+ struct A { // expected-note {{subexpression}}
+ int k = X<A().k>::n; // expected-error {{defaulted default constructor of 'A' cannot be used}} expected-error {{not a constant expression}} expected-note {{in call to 'A()'}}
+ };
+
+ // FIXME: The "constexpr constructor must initialize all members" diagnostic
+ // here is bogus (we discard the k(k) initializer because the parameter 'k'
+ // has been marked invalid).
+ struct B { // expected-note 2{{candidate}}
+ constexpr B( // expected-error {{must initialize all members}} expected-note {{candidate}}
+ int k = X<B().k>::n) : // expected-error {{no matching constructor}}
+ k(k) {}
+ int k; // expected-note {{not initialized}}
+ };
+}
More information about the cfe-commits
mailing list