#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "clang/Analysis/FlowSensitive/StorageLocation.h"
#include "clang/Analysis/FlowSensitive/Value.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/StringRef.h"
}
auto isOptionalNulloptConstructor() {
- return cxxConstructExpr(hasOptionalType(), argumentCountIs(1),
- hasArgument(0, hasNulloptType()));
+ return cxxConstructExpr(
+ hasOptionalType(),
+ hasDeclaration(cxxConstructorDecl(parameterCountIs(1),
+ hasParameter(0, hasNulloptType()))));
}
auto isOptionalInPlaceConstructor() {
BoolValue &valueOrConversionHasValue(const FunctionDecl &F, const Expr &E,
const MatchFinder::MatchResult &MatchRes,
LatticeTransferState &State) {
+ assert(F.getTemplateSpecializationArgs() != nullptr);
assert(F.getTemplateSpecializationArgs()->size() > 0);
const int TemplateParamOptionalWrappersCount = countOptionalWrappers(
)");
}
+TEST_P(UncheckedOptionalAccessTest, NulloptConstructorWithSugaredType) {
+ ExpectDiagnosticsFor(
+ R"(
+ #include "unchecked_optional_access_test.h"
+ template <typename T>
+ using wrapper = T;
+
+ template <typename T>
+ wrapper<T> wrap(T);
+
+ void target() {
+ $ns::$optional<int> opt(wrap($ns::nullopt));
+ opt.value(); // [[unsafe]]
+ }
+ )");
+}
+
TEST_P(UncheckedOptionalAccessTest, InPlaceConstructor) {
ExpectDiagnosticsFor(R"(
#include "unchecked_optional_access_test.h"