Skip to content

Commit af8eadc

Browse files
committed
[clang][bytecode] Diagnose heap-allocated array elem pointers...
... as "pointer to subobject".
1 parent 0af2614 commit af8eadc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/AST/ByteCode/EvaluationResult.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ bool EvaluationResult::checkReturnValue(InterpState &S, const Context &Ctx,
230230
assert(B->getDescriptor());
231231
assert(B->getDescriptor()->asExpr());
232232

233+
bool IsSubobj = !Ptr.isRoot() || Ptr.isArrayElement();
233234
S.FFDiag(Info, diag::note_constexpr_dynamic_alloc)
234-
<< Ptr.getType()->isReferenceType() << !Ptr.isRoot();
235+
<< Ptr.getType()->isReferenceType() << IsSubobj;
235236
S.Note(B->getDescriptor()->asExpr()->getExprLoc(),
236237
diag::note_constexpr_dynamic_alloc_here);
237238
return false;

clang/test/AST/ByteCode/new-delete.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ namespace std {
619619
}
620620
}
621621

622+
constexpr int *escape = std::allocator<int>().allocate(3); // both-error {{constant expression}} \
623+
// both-note {{pointer to subobject of heap-allocated}} \
624+
// both-note {{heap allocation performed here}}
625+
622626
/// Specialization for float, using operator new/delete.
623627
namespace std {
624628
using size_t = decltype(sizeof(0));

0 commit comments

Comments
 (0)