summaryrefslogtreecommitdiffstats
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-02-08 08:11:33 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-02-08 08:11:33 +0000
commit2fd5983e0da447291a651a347c206aee37a1de5f (patch)
tree99be68f5832576df228e2736d86c27a4e4d212fe /lib/AST/ExprConstant.cpp
parentcfa8e6530dbc5ed6147281be78bc319dea928d76 (diff)
Implement DR1458: Taking the address of an object of incomplete class type is
not a constant expression, because we can't tell whether the complete class type will have an overloaded operator&. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150066 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 410406788d..48e0c6f7da 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -2937,6 +2937,18 @@ bool PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
}
bool PointerExprEvaluator::VisitUnaryAddrOf(const UnaryOperator *E) {
+ QualType SrcTy = E->getSubExpr()->getType();
+ // In C++, taking the address of an object of incomplete class type has
+ // undefined behavior if the complete class type has an overloaded operator&.
+ // DR1458 makes such expressions non-constant.
+ if (Info.getLangOpts().CPlusPlus &&
+ SrcTy->isRecordType() && SrcTy->isIncompleteType()) {
+ const RecordType *RT = SrcTy->getAs<RecordType>();
+ Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_addr_of_incomplete, 1)
+ << SrcTy;
+ Info.Note(RT->getDecl()->getLocation(), diag::note_forward_declaration)
+ << RT->getDecl();
+ }
return EvaluateLValue(E->getSubExpr(), Result, Info);
}