================
@@ -347,6 +361,30 @@ static bool shouldTrackFirstArgument(const FunctionDecl
*FD) {
return false;
}
+// Returns true if we should perform the GSL analysis on the first argument for
+// the given constructor.
+static bool
+shouldTrackFirstArgumentForConstructor(const CXXConstructExpr *Ctor) {
+ const auto *ClassD = Ctor->getConstructor()->getParent();
+
+ auto FirstArgType = Ctor->getArg(0)->getType();
+ // Case 1, construct a GSL pointer, e.g. std::string_view
+ if (ClassD->hasAttr<PointerAttr>())
+ return true;
+
+ // case 2: construct a container of pointer (std::vector<std::string_view>)
+ // from an owner or a std::initilizer_list.
+ //
+ // std::initializer_list is a proxy object that provides access to the
backing
+ // array. We perform analysis on it to determine if there are any dangling
+ // temporaries in the backing array.
+ if (Ctor->getConstructor()->getNumParams() != 1 ||
+ !isContainerOfPointer(ClassD))
+ return false;
+ return isGSLOwner(FirstArgType) ||
+ isStdInitializerListOfPointer(FirstArgType->getAsRecordDecl());
----------------
usx95 wrote:
(This might be potentially wrong)
It looks like we mean to say that `std::initialiser_list<Pointer>` should be
considered as GSL Owner.
Can we try making this more general and move
`isStdInitializerListOfPointer(FirstArgType->getAsRecordDecl())` into
`isGSLOwner` ? Even if it doesn't work, I would like to know some case where
this doesn't work for my understanding.
https://github.com/llvm/llvm-project/pull/108344
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits