1"""
2Tests that rvalue references are supported in C++
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class RvalueReferencesTestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    # rdar://problem/11479676
16    @expectedFailureAll(
17        compiler="icc",
18        bugnumber="ICC (13.1, 14-beta) do not emit DW_TAG_rvalue_reference_type.")
19    def test_with_run_command(self):
20        """Test that rvalues are supported in the C++ expression parser"""
21        self.build()
22        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
23
24        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
25        self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
26
27        self.runCmd("process launch", RUN_SUCCEEDED)
28
29        # Note that clang as of r187480 doesn't emit DW_TAG_const_type, unlike gcc 4.8.1
30        # With gcc 4.8.1, lldb reports the type as (int &&const)
31        self.expect("frame variable i",
32                    startstr="(int &&",
33                    substrs=["i = 0x", "&i = 3"])
34
35        self.expect("expression -- i",
36                    startstr="(int) ",
37                    substrs=["3"])
38
39        self.expect("breakpoint delete 1")
40
41        self.runCmd("process continue")
42
43        self.expect("expression -- foo(2)")
44
45        self.expect("expression -- int &&j = 3; foo(j)",
46                    error=True)
47
48        self.expect("expression -- int &&k = 6; k",
49                    startstr="(int) $1 = 6")
50
51    def set_breakpoint(self, line):
52        lldbutil.run_break_set_by_file_and_line(
53            self, "main.cpp", line, num_expected_locations=1, loc_exact=True)
54