aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ExpressionParser
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2026-02-06 16:44:49 +0000
committerGitHub <noreply@github.com>2026-02-06 16:44:49 +0000
commit68d704844575d166301cf579b77b947fbe3446bb (patch)
tree42b917c06130ce1db538e33502fb4e047c9d122b /lldb/source/Plugins/ExpressionParser
parent115158b176b89b5a97938c842122b7cde6f7a72d (diff)
downloadllvm-68d704844575d166301cf579b77b947fbe3446bb.tar.gz
llvm-68d704844575d166301cf579b77b947fbe3446bb.tar.bz2
llvm-68d704844575d166301cf579b77b947fbe3446bb.zip
[lldb][ClangUserExpression] Emit workaround hint when trying to call function templates (#179916)
Before: ``` (lldb) expression some_template_func<int, long>(5) ˄ ╰─ error: 'some_template_func' does not name a template but is followed by template arguments note: Ran expression as 'C++14'. note: note: non-template declaration found by name lookup ``` After: ``` (lldb) expression some_template_func<int, long>(5) ˄ ╰─ error: 'some_template_func' does not name a template but is followed by template arguments note: Ran expression as 'C++14'. note: note: non-template declaration found by name lookup note: Naming template instantiation not yet supported. Template functions can be invoked via their mangled name. E.g., expression _Z3fooIiEvi(5) ``` There isn't a great way to get to the actual function being named (and its mangled name) since we're just dealing with raw text. So I just print an example mangled name. This doesn't work for all template instantiations. E.g.,: ``` (lldb) p f.method<long>(10) ˄ ˄ │ ╰─ error: expected '(' for function-style cast or type construction ╰─ error: no member named 'method' in 'Foo<int>' note: Ran expression as 'C++14'. ``` This is a consequence of how we construct the AST for template methods. Once we fix that, this hint will get emitted there too. Note this will also trigger in cases where no function is being called (hence I used the defensive phrase "Template functions can be invoked"). rdar://135725807
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp25
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h3
2 files changed, 28 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
index 239280c65255..4fcc640d9071 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -56,6 +56,7 @@
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/DiagnosticSema.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/Dwarf.h"
@@ -988,9 +989,33 @@ void ClangUserExpression::FixupCVRParseErrorDiagnostics(
!m_fixed_text.empty() ? m_fixed_text.c_str() : m_expr_text.c_str());
}
+void ClangUserExpression::FixupTemplateLookupDiagnostics(
+ DiagnosticManager &diagnostic_manager) const {
+ if (llvm::none_of(diagnostic_manager.Diagnostics(),
+ [](std::unique_ptr<Diagnostic> const &diag) {
+ switch (diag->GetCompilerID()) {
+ // FIXME: should we also be checking
+ // clang::diag::err_no_member_template?
+ case clang::diag::err_no_template:
+ case clang::diag::err_non_template_in_template_id:
+ return true;
+ default:
+ return false;
+ }
+ }))
+ return;
+
+ diagnostic_manager.AddDiagnostic(
+ "Naming template instantiation not yet supported. Template functions "
+ "can be invoked via their mangled name. For example, using "
+ "`_Z3fooIiEvi(123)` for `foo<int>(123)`",
+ lldb::eSeverityInfo, eDiagnosticOriginLLDB);
+}
+
void ClangUserExpression::FixupParseErrorDiagnostics(
DiagnosticManager &diagnostic_manager) const {
FixupCVRParseErrorDiagnostics(diagnostic_manager);
+ FixupTemplateLookupDiagnostics(diagnostic_manager);
}
char ClangUserExpression::ClangUserExpressionHelper::ID;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
index fd24893b1ecd..74aceed1d637 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
@@ -215,6 +215,9 @@ private:
void
FixupCVRParseErrorDiagnostics(DiagnosticManager &diagnostic_manager) const;
+ void
+ FixupTemplateLookupDiagnostics(DiagnosticManager &diagnostic_manager) const;
+
/// Defines how the current expression should be wrapped.
ClangExpressionSourceCode::WrapKind GetWrapKind() const;
bool SetupPersistentState(DiagnosticManager &diagnostic_manager,