Skip to content

Commit 5f88f39

Browse files
committed
[lldb] Enable C++14 when evaluating expressions in a C++14 frame
Summary: Currently we never enable C++14 in the expression evaluator. This enables it when the language of the program is C++14. It seems C++17 and so on isn't yet in any of the language enums (and the DWARF standard it seems), so C++17 support will be a follow up patch. Reviewers: labath, JDevlieghere Reviewed By: labath, JDevlieghere Subscribers: aprantl Differential Revision: https://reviews.llvm.org/D80308
1 parent bca378f commit 5f88f39

File tree

7 files changed

+55
-1
lines changed

7 files changed

+55
-1
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,11 @@ ClangExpressionParser::ClangExpressionParser(
491491
// be re-evaluated in the future.
492492
lang_opts.CPlusPlus11 = true;
493493
break;
494+
case lldb::eLanguageTypeC_plus_plus_14:
495+
lang_opts.CPlusPlus14 = true;
496+
LLVM_FALLTHROUGH;
494497
case lldb::eLanguageTypeC_plus_plus:
495498
case lldb::eLanguageTypeC_plus_plus_11:
496-
case lldb::eLanguageTypeC_plus_plus_14:
497499
lang_opts.CPlusPlus11 = true;
498500
m_compiler->getHeaderSearchOpts().UseLibcxx = true;
499501
LLVM_FALLTHROUGH;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CXX_SOURCES := main.cpp
2+
CXXFLAGS_EXTRAS := -std=c++11
3+
4+
include Makefile.rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
class TestCase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
10+
def test(self):
11+
self.build()
12+
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
13+
14+
# Run an expression that is valid in C++11 (as it uses nullptr).
15+
self.expect_expr("nullptr == nullptr", result_type="bool", result_value="true")
16+
17+
# Run a expression that is not valid in C++11 (as it uses polymorphic
18+
# lambdas from C++14).
19+
self.expect("expr [](auto x) { return x; }(1)", error=True, substrs=["'auto' not allowed in lambda parameter"])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main() {
2+
return 0; // break here
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CXX_SOURCES := main.cpp
2+
CXXFLAGS_EXTRAS := -std=c++14
3+
4+
include Makefile.rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
class TestCase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
10+
def test(self):
11+
self.build()
12+
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
13+
14+
# Run an expression that is valid in C++11 (as it uses nullptr).
15+
self.expect_expr("nullptr == nullptr", result_type="bool", result_value="true")
16+
17+
# Run a expression that is only valid in C++14 that (as it uses
18+
# polymorphic lambdas).
19+
self.expect_expr("[](auto x) { return x; }(1)", result_type="int", result_value="1")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main() {
2+
return 0; // break here
3+
}

0 commit comments

Comments
 (0)