================
@@ -1839,6 +1839,41 @@ static void handleRestrictAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
                  RestrictAttr(S.Context, AL, DeallocE, DeallocPtrIdx));
 }
 
+static bool isSpanLikeType(const QualType &Ty) {
+  // Check that the type is a plain record with one field being a pointer
+  // type and the other field being an integer. This matches the common
+  // implementation of std::span or sized_allocation_t in P0901R11.
+  // Note that there may also be numerous cases of pointer+integer structures
+  // not actually exhibiting a span-like semantics, so sometimes
+  // this heuristic expectedly leads to false positive results.
+  const RecordDecl *RD = Ty->getAsRecordDecl();
+  if (!RD || RD->isUnion())
+    return false;
+  const RecordDecl *Def = RD->getDefinition();
+  if (!Def)
+    return false; // This is an incomplete type.
+  auto FieldsBegin = Def->field_begin();
+  if (std::distance(FieldsBegin, Def->field_end()) != 2)
+    return false;
+  const QualType FirstFieldType = FieldsBegin->getType();
+  const QualType SecondFieldType = std::next(FieldsBegin)->getType();
+  // Verify two possible orderings.
+  return (FirstFieldType->isAnyPointerType() &&
+          SecondFieldType->isIntegerType()) ||
+         (FirstFieldType->isIntegerType() &&
+          SecondFieldType->isAnyPointerType());
+}
+
+static void handleMallocSpanAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  QualType ResultType = getFunctionOrMethodResultType(D);
----------------
a-nogikh wrote:

I've added tests for trailing return types - they already work fine.
(And simplified the dependent type implementation as you suggested in other 
comments).

https://github.com/llvm/llvm-project/pull/167010
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to