|
@@ -170,7 +170,15 @@ template<typename T>
|
|
struct optional {
|
|
struct optional {
|
|
optional();
|
|
optional();
|
|
optional(const T&);
|
|
optional(const T&);
|
|
- T &operator*();
|
|
|
|
|
|
+ T &operator*() &;
|
|
|
|
+ T &&operator*() &&;
|
|
|
|
+ T &value() &;
|
|
|
|
+ T &&value() &&;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+template<typename T>
|
|
|
|
+struct stack {
|
|
|
|
+ T &top();
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -188,6 +196,16 @@ const char *danglingRawPtrFromLocal() {
|
|
return s.c_str(); // expected-warning {{address of stack memory associated with local variable 's' returned}}
|
|
return s.c_str(); // expected-warning {{address of stack memory associated with local variable 's' returned}}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int &danglingRawPtrFromLocal2() {
|
|
|
|
+ std::optional<int> o;
|
|
|
|
+ return o.value(); // expected-warning {{reference to stack memory associated with local variable 'o' returned}}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int &danglingRawPtrFromLocal3() {
|
|
|
|
+ std::optional<int> o;
|
|
|
|
+ return *o; // expected-warning {{reference to stack memory associated with local variable 'o' returned}}
|
|
|
|
+}
|
|
|
|
+
|
|
const char *danglingRawPtrFromTemp() {
|
|
const char *danglingRawPtrFromTemp() {
|
|
return std::basic_string<char>().c_str(); // expected-warning {{returning address of local temporary object}}
|
|
return std::basic_string<char>().c_str(); // expected-warning {{returning address of local temporary object}}
|
|
}
|
|
}
|
|
@@ -203,9 +221,10 @@ int *danglingUniquePtrFromTemp2() {
|
|
}
|
|
}
|
|
|
|
|
|
void danglingReferenceFromTempOwner() {
|
|
void danglingReferenceFromTempOwner() {
|
|
- int &r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
|
|
- int &r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
|
|
- int &r3 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
|
|
|
|
+ int &&r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
|
|
+ int &&r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
|
|
+ int &&r3 = std::optional<int>(5).value(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
|
|
+ int &r4 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
|
}
|
|
}
|
|
|
|
|
|
std::vector<int> getTempVec();
|
|
std::vector<int> getTempVec();
|