================
@@ -1839,6 +1839,70 @@ static void handleRestrictAttr(Sema &S, Decl *D, const
ParsedAttr &AL) {
RestrictAttr(S.Context, AL, DeallocE, DeallocPtrIdx));
}
+bool Sema::CheckSpanLikeType(const AttributeCommonInfo &CI,
+ const QualType &Ty) {
+ // Note that there may also be numerous cases of pointer + integer /
+ // pointer + pointer / integer + pointer structures not actually exhibiting
+ // a span-like semantics, so sometimes these heuristics expectedly
+ // lead to false positive results.
+ auto emitWarning = [this, &CI](unsigned NoteDiagID) {
+ Diag(CI.getLoc(), diag::warn_attribute_return_span_only) << CI;
+ return Diag(CI.getLoc(), NoteDiagID);
+ };
+ if (Ty->isDependentType())
+ return false;
+ // isCompleteType is used to force template class instantiation.
+ if (!isCompleteType(CI.getLoc(), Ty))
+ return emitWarning(diag::note_returned_incomplete_type);
+ const RecordDecl *RD = Ty->getAsRecordDecl();
+ if (!RD || RD->isUnion())
+ return emitWarning(diag::note_returned_not_struct);
+ if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
+ if (CXXRD->getNumBases() > 0) {
----------------
AaronBallman wrote:
I think we also need a check `CXXRD->getNumVBases() > 0` as well, and a test
using virtual base classes but not a normal base class.
https://github.com/llvm/llvm-project/pull/167010
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits