[clang][bytecode] Diagnose heap-allocated array elem pointers... (#137523)
... as "pointer to subobject".
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index d603e08..f59612b 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -230,8 +230,9 @@
assert(B->getDescriptor());
assert(B->getDescriptor()->asExpr());
+ bool IsSubobj = !Ptr.isRoot() || Ptr.isArrayElement();
S.FFDiag(Info, diag::note_constexpr_dynamic_alloc)
- << Ptr.getType()->isReferenceType() << !Ptr.isRoot();
+ << Ptr.getType()->isReferenceType() << IsSubobj;
S.Note(B->getDescriptor()->asExpr()->getExprLoc(),
diag::note_constexpr_dynamic_alloc_here);
return false;
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index 21d6546..6726659 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -620,6 +620,10 @@
}
}
+constexpr int *escape = std::allocator<int>().allocate(3); // both-error {{constant expression}} \
+ // both-note {{pointer to subobject of heap-allocated}} \
+ // both-note {{heap allocation performed here}}
+
/// Specialization for float, using operator new/delete.
namespace std {
using size_t = decltype(sizeof(0));