mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 06:18:11 +00:00
Use the plain identifier for Carbon names in C++ (#7897)
C++ interop used `GetFormatted` to turn a Carbon name into a C++ name. For an identifier that is a Carbon keyword, such as `base`, `GetFormatted` adds an `r#` prefix, so the C++ name came out as `r#base` instead of `base`. This showed up in three places: - A failed call to the C++ function `base` was reported as "no matching function for call to 'r#base'". - An exported Carbon function was mangled as `_ZN6CarbonL6r#baseEv` instead of `_ZN6CarbonL4baseEv`. - Its thunk was named `r#base__carbon_thunk` instead of `base__carbon_thunk`. All three now use `GetClangIdentifierInfo`, which `export.cpp` already uses for other C++ names. The name is always an identifier in these places: an overload set is only imported by looking up an identifier in C++, and only functions declared in Carbon are exported, which are always named by an identifier. So they check for an identifier, as the export of a class name already does, rather than falling back to `GetFormatted`. This removes a TODO about naming a `NameId::CppOperator` overload set, which can't happen: C++ operators are resolved in `operators.cpp` without an overload set. Assisted-by: Claude Code
This commit is contained in:
1 parent
8f258eaaa6
commit
c1e83b0b78
4 files changed
+124
-11
No files matched your search
@@ -78,6 +78,24 @@ fn MyF() {
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// --- fail_import_special_name_call_escaped_no_match.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "special_name.h";
|
||||
|
||||
fn MyF() {
|
||||
// CHECK:STDERR: fail_import_special_name_call_escaped_no_match.carbon:[[@LINE+8]]:15: error: no matching function for call to 'base' [CppInteropParseError]
|
||||
// CHECK:STDERR: 15 | Cpp.r#base(1);
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: fail_import_special_name_call_escaped_no_match.carbon:[[@LINE-6]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./special_name.h:2:6: note: candidate function not viable: requires 0 arguments, but 1 was provided [CppInteropParseNote]
|
||||
// CHECK:STDERR: 2 | auto base() -> void;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.r#base(1);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Overloaded
|
||||
// ============================================================================
|
||||
|
||||
Reference in new issue
Block a user