From: Richard Smith Date: Fri, 10 Feb 2012 07:41:06 +0000 (+0000) Subject: Update to new resolution for DR1458. When taking the address of an object of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=864b1cf13b288c5099911e1265431ffdcac060a4;p=clang Update to new resolution for DR1458. When taking the address of an object of incomplete class type which has an overloaded operator&, it's now just unspecified whether the overloaded operator or the builtin is used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150234 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticASTKinds.td b/include/clang/Basic/DiagnosticASTKinds.td index 80d9329172..fb6e73090e 100644 --- a/include/clang/Basic/DiagnosticASTKinds.td +++ b/include/clang/Basic/DiagnosticASTKinds.td @@ -55,9 +55,6 @@ def note_constexpr_pointer_comparison_differing_access : Note< "specifiers (%1 vs %3) has unspecified value">; def note_constexpr_compare_virtual_mem_ptr : Note< "comparison of pointer to virtual member function %0 has unspecified value">; -def note_constexpr_addr_of_incomplete : Note< - "cannot take address of object of incomplete class type %0 " - "in a constant expression">; def note_constexpr_past_end : Note< "dereferenced pointer past the end of %select{|subobject of }0" "%select{temporary|%2}1 is not a constant expression">; diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index e43884e376..998bb705f9 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2944,18 +2944,6 @@ 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(); - 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); } diff --git a/test/CXX/expr/expr.const/p2-0x.cpp b/test/CXX/expr/expr.const/p2-0x.cpp index 43d683aeca..2d4f4fb62e 100644 --- a/test/CXX/expr/expr.const/p2-0x.cpp +++ b/test/CXX/expr/expr.const/p2-0x.cpp @@ -111,9 +111,10 @@ namespace RecursionLimits { // DR1458: taking the address of an object of incomplete class type namespace IncompleteClassTypeAddr { - struct S; // expected-note {{forward}} + struct S; extern S s; - constexpr S *p = &s; // expected-error {{constant expression}} expected-note {{cannot take address of object of incomplete class type 'IncompleteClassTypeAddr::S' in a constant expression}} + constexpr S *p = &s; // ok + static_assert(p, ""); extern S sArr[]; constexpr S (*p2)[] = &sArr; // ok @@ -121,7 +122,7 @@ namespace IncompleteClassTypeAddr { struct S { constexpr S *operator&() { return nullptr; } }; - constexpr S *q = &s; + constexpr S *q = &s; // ok static_assert(!q, ""); }