Skip to content

Commit e7b71c0

Browse files
Add a failing test for user-defined literals in macros (#6431)
These types of literals are not supported at the moment, adding a `todo` test for it. Part of #6303
1 parent a179bd4 commit e7b71c0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

toolchain/check/testdata/interop/cpp/macros.carbon

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,41 @@ fn F() {
608608
Cpp.foo(Cpp.MyNullPtr);
609609
}
610610

611+
// --- user_defined_literal.h
612+
constexpr auto operator""_kb(unsigned long long k) -> unsigned long long {
613+
return k * 1024;
614+
}
615+
#define M_1KB 1_kb
616+
617+
// --- fail_todo_import_user_defined_literal.carbon
618+
619+
library "[[@TEST_NAME]]";
620+
621+
// CHECK:STDERR: fail_todo_import_user_defined_literal.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
622+
// CHECK:STDERR: ./user_defined_literal.h:4:16: error: no matching literal operator for call to 'operator""_kb' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template [CppInteropParseError]
623+
// CHECK:STDERR: 4 | #define M_1KB 1_kb
624+
// CHECK:STDERR: | ^
625+
import Cpp library "user_defined_literal.h";
626+
627+
fn F() {
628+
// CHECK:STDERR: fail_todo_import_user_defined_literal.carbon:[[@LINE+15]]:2: note: in `Cpp` name lookup for `M_1KB` [InCppNameLookup]
629+
// CHECK:STDERR: Cpp.M_1KB;
630+
// CHECK:STDERR: ^~~~~~~~~
631+
// CHECK:STDERR:
632+
// CHECK:STDERR: fail_todo_import_user_defined_literal.carbon:[[@LINE+11]]:2: error: failed to parse macro Cpp.M_1KB to a valid constant expression [InCppMacroEvaluation]
633+
// CHECK:STDERR: Cpp.M_1KB;
634+
// CHECK:STDERR: ^~~~~~~~~
635+
// CHECK:STDERR: fail_todo_import_user_defined_literal.carbon:[[@LINE+8]]:2: note: in `Cpp` name lookup for `M_1KB` [InCppNameLookup]
636+
// CHECK:STDERR: Cpp.M_1KB;
637+
// CHECK:STDERR: ^~~~~~~~~
638+
// CHECK:STDERR:
639+
// CHECK:STDERR: fail_todo_import_user_defined_literal.carbon:[[@LINE+4]]:2: error: member name `M_1KB` not found in `Cpp` [MemberNameNotFoundInInstScope]
640+
// CHECK:STDERR: Cpp.M_1KB;
641+
// CHECK:STDERR: ^~~~~~~~~
642+
// CHECK:STDERR:
643+
Cpp.M_1KB;
644+
}
645+
611646
// --- enums.carbon
612647

613648
library "[[@TEST_NAME]]";

0 commit comments

Comments
 (0)