diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-08 08:11:33 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-08 08:11:33 +0000 |
commit | 90cacbbf3efda3745dd7c10e8f891956bfaf031e (patch) | |
tree | a951db452ff6b01ba4f07ac4b7b293d9b26ea8a6 /clang/lib/AST/ExprConstant.cpp | |
parent | 13f118f47b6d1faf9ea41d53b5ebb1e965cd3696 (diff) | |
download | bcm5719-llvm-90cacbbf3efda3745dd7c10e8f891956bfaf031e.tar.gz bcm5719-llvm-90cacbbf3efda3745dd7c10e8f891956bfaf031e.zip |
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&.
llvm-svn: 150066
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 410406788dc..48e0c6f7daa 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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); } |