Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test lldb data formatter for LibStdC++ std::variant.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand Down Expand Up @@ -62,17 +61,13 @@ def test_with_run_command(self):
"frame variable v3",
substrs=["v3 = Active Type = char {", "Value = 'A'", "}"],
)
"""
TODO: temporarily disable No Value tests as they seem to fail on ubuntu/debian
bots. Pending reproduce and investigation.

self.expect("frame variable v_no_value", substrs=["v_no_value = No Value"])
self.expect("frame variable v_valueless", substrs=["v_valueless = No Value"])

self.expect(
"frame variable v_many_types_no_value",
substrs=["v_many_types_no_value = No Value"],
"frame variable v_many_types_valueless",
substrs=["v_many_types_valueless = No Value"],
)
"""

@add_test_categories(["libstdcxx"])
def test_invalid_variant_index(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <vector>

struct S {
operator int() { throw 42; }
S() = default;
S(S &&) { throw 42; }
S &operator=(S &&) = default;
};

int main() {
Expand All @@ -21,7 +23,7 @@ int main() {
std::variant<int, double, char> v2;
std::variant<int, double, char> v3;
std::variant<std::variant<int, double, char>> v_v1;
std::variant<int, double, char> v_no_value;
std::variant<int, char, S> v_valueless = 5;
// The next variant has many types, meaning the type index does not fit in
// a byte and must be `unsigned short` instead of `unsigned char` when
// using the unstable libc++ ABI. With stable libc++ ABI, the type index
Expand All @@ -43,8 +45,11 @@ int main() {
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int>
v_many_types_no_value;
int, int, int, int, int, int, int, int, int, int, int, int, S>
v_many_types_valueless;

v_valueless = 5;
v_many_types_valueless.emplace<0>(10);

v1 = 12; // v contains int
v1_typedef = v1;
Expand All @@ -67,18 +72,22 @@ int main() {
printf("%f\n", d); // break here

try {
v_no_value.emplace<0>(S());
// Exception in type-changing move-assignment is guaranteed to put
// std::variant into a valueless state.
v_valueless = S();
} catch (...) {
}

printf("%zu\n", v_no_value.index());
printf("%d\n", v_valueless.valueless_by_exception());

try {
v_many_types_no_value.emplace<0>(S());
// Exception in move-assignment is guaranteed to put std::variant into a
// valueless state.
v_many_types_valueless = S();
} catch (...) {
}

printf("%zu\n", v_many_types_no_value.index());
printf("%d\n", v_many_types_valueless.valueless_by_exception());

return 0; // break here
}
Loading