Rename and rearrange entities in tests to avoid name reuse (#7656)

Fix a bunch of cases where we use the same external name to mean
multiple different things in the same test. We've historically gotten
away with this, but under `--share-cpp-ast`, it becomes an error, at
least if the entity is either defined in, or used from, C++ code.

Assisted-by: Gemini via Antigravity (original change) and Claude Code
(suggested edits in review)

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Richard Smith
2026-08-21 01:36:40 +00:00
committed by GitHub
co-authored by Chandler Carruth
parent 6eb900dff5
commit c588eadb57
53 changed files with 7794 additions and 7705 deletions
+56 -56
View File
@@ -32,23 +32,23 @@ library "[[@TEST_NAME]]";
import Cpp;
base class A {
base class LookupBase {
fn F();
fn G(n: i32);
}
class B {
extend base: A;
class LookupDerived {
extend base: LookupBase;
fn G();
}
inline Cpp '''
void Qualified() {
Carbon::B::F();
Carbon::B::G();
Carbon::LookupDerived::F();
Carbon::LookupDerived::G();
}
void MemberAccess(Carbon::A *a, Carbon::B *b) {
void MemberAccess(Carbon::LookupBase *a, Carbon::LookupDerived *b) {
b->F();
b->G();
}
@@ -59,17 +59,17 @@ library "[[@TEST_NAME]]";
import Cpp;
class Final {}
class FinalClass {}
inline Cpp '''
// CHECK:STDERR: fail_derive_from_final.carbon:[[@LINE+7]]:12: error: base 'Final' is marked 'final' [CppInteropParseError]
// CHECK:STDERR: 15 | struct A : Carbon::Final {};
// CHECK:STDERR: fail_derive_from_final.carbon:[[@LINE+7]]:12: error: base 'FinalClass' is marked 'final' [CppInteropParseError]
// CHECK:STDERR: 15 | struct A : Carbon::FinalClass {};
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_derive_from_final.carbon:[[@LINE-6]]:13: note: 'Final' declared here [CppInteropParseNote]
// CHECK:STDERR: 5 | class Final {}
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_derive_from_final.carbon:[[@LINE-6]]:18: note: 'FinalClass' declared here [CppInteropParseNote]
// CHECK:STDERR: 5 | class FinalClass {}
// CHECK:STDERR: | ^
// CHECK:STDERR:
struct A : Carbon::Final {};
struct A : Carbon::FinalClass {};
''';
// --- fail_abstract.carbon
@@ -84,23 +84,23 @@ struct VirtualDestructor {
};
''';
// CHECK:STDERR: fail_abstract.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `Abstract` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class Abstract {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_abstract.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `AbstractWithVdtor` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class AbstractWithVdtor {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
abstract class Abstract {
abstract class AbstractWithVdtor {
extend base: Cpp.VirtualDestructor;
}
inline Cpp '''
// CHECK:STDERR: fail_abstract.carbon:[[@LINE+7]]:18: error: variable type 'Carbon::Abstract' is an abstract class [CppInteropParseError]
// CHECK:STDERR: 28 | Carbon::Abstract x;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_abstract.carbon:[[@LINE-8]]:25: note: unimplemented pure virtual method '~Abstract' in 'Abstract' [CppInteropParseNote]
// CHECK:STDERR: 16 | abstract class Abstract {
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_abstract.carbon:[[@LINE+7]]:27: error: variable type 'Carbon::AbstractWithVdtor' is an abstract class [CppInteropParseError]
// CHECK:STDERR: 28 | Carbon::AbstractWithVdtor x;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_abstract.carbon:[[@LINE-8]]:34: note: unimplemented pure virtual method '~AbstractWithVdtor' in 'AbstractWithVdtor' [CppInteropParseNote]
// CHECK:STDERR: 16 | abstract class AbstractWithVdtor {
// CHECK:STDERR: | ^
// CHECK:STDERR:
Carbon::Abstract x;
Carbon::AbstractWithVdtor x;
''';
// --- fail_todo_abstract_nonvirtual_dtor.carbon
@@ -111,17 +111,17 @@ import Cpp;
// TODO: Find a way to export this to C++ as an abstract class, despite not
// having a vptr.
// CHECK:STDERR: fail_todo_abstract_nonvirtual_dtor.carbon:[[@LINE+8]]:1: error: semantics TODO: `exporting abstract class with no abstract methods and non-virtual destructor to C++` [SemanticsTodo]
// CHECK:STDERR: abstract class Abstract {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: abstract class AbstractNonvirtualDtor {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_todo_abstract_nonvirtual_dtor.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `Abstract` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class Abstract {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_todo_abstract_nonvirtual_dtor.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `AbstractNonvirtualDtor` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class AbstractNonvirtualDtor {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
abstract class Abstract {}
abstract class AbstractNonvirtualDtor {}
inline Cpp '''
class Derived : public Carbon::Abstract {};
class DerivedNonvirtualDtor : public Carbon::AbstractNonvirtualDtor {};
''';
// --- fail_todo_abstract_nonvirtual_dtor_but_virtual_fns.carbon
@@ -132,16 +132,16 @@ import Cpp;
// TODO: We should support generating a base subobject destructor for an
// abstract class, even though we refuse to generate a complete object
// destructor.
// CHECK:STDERR: fail_todo_abstract_nonvirtual_dtor_but_virtual_fns.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `Abstract` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class Abstract {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_todo_abstract_nonvirtual_dtor_but_virtual_fns.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `AbstractWithMethodNoVptr` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class AbstractWithMethodNoVptr {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
abstract class Abstract {
abstract class AbstractWithMethodNoVptr {
abstract fn F(self);
}
inline Cpp '''
class Derived : public Carbon::Abstract {
class DerivedWithMethodNoVptr : public Carbon::AbstractWithMethodNoVptr {
};
''';
@@ -153,23 +153,23 @@ import Cpp;
// TODO: We should support generating a base subobject destructor for an
// abstract class, even though we refuse to generate a complete object
// destructor.
// CHECK:STDERR: fail_variable_with_abstract_method.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `Abstract` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class Abstract {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_variable_with_abstract_method.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `AbstractWithMethod` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class AbstractWithMethod {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
abstract class Abstract {
abstract class AbstractWithMethod {
abstract fn F(self);
}
inline Cpp '''
// CHECK:STDERR: fail_variable_with_abstract_method.carbon:[[@LINE+7]]:18: error: variable type 'Carbon::Abstract' is an abstract class [CppInteropParseError]
// CHECK:STDERR: 24 | Carbon::Abstract x;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_variable_with_abstract_method.carbon:[[@LINE-7]]:22: note: unimplemented pure virtual method 'F' in 'Abstract' [CppInteropParseNote]
// CHECK:STDERR: fail_variable_with_abstract_method.carbon:[[@LINE+7]]:28: error: variable type 'Carbon::AbstractWithMethod' is an abstract class [CppInteropParseError]
// CHECK:STDERR: 24 | Carbon::AbstractWithMethod x_abstract;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_variable_with_abstract_method.carbon:[[@LINE-7]]:22: note: unimplemented pure virtual method 'F' in 'AbstractWithMethod' [CppInteropParseNote]
// CHECK:STDERR: 13 | abstract fn F(self);
// CHECK:STDERR: | ^
// CHECK:STDERR:
Carbon::Abstract x;
Carbon::AbstractWithMethod x_abstract;
''';
// --- fail_todo_abstract_method_overridden_in_cpp.carbon
@@ -180,20 +180,20 @@ import Cpp;
// TODO: We should support generating a base subobject destructor for an
// abstract class, even though we refuse to generate a complete object
// destructor.
// CHECK:STDERR: fail_todo_abstract_method_overridden_in_cpp.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `Abstract` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class Abstract {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_todo_abstract_method_overridden_in_cpp.carbon:[[@LINE+4]]:1: error: cannot access member of interface `Core.Destroy` in type `AbstractToOverride` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: abstract class AbstractToOverride {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
abstract class Abstract {
abstract class AbstractToOverride {
abstract fn F(ref self);
}
// A C++ class that overrides the abstract method can be instantiated.
inline Cpp '''
struct Derived : Carbon::Abstract {
struct DerivedOverriding : Carbon::AbstractToOverride {
void F() & override {}
};
Derived d;
DerivedOverriding d;
''';
// --- override_virtual_dtor.carbon
@@ -202,15 +202,15 @@ library "[[@TEST_NAME]]";
import Cpp;
inline Cpp '''
struct A {
virtual ~A() = 0;
struct BaseWithPureVdtor {
virtual ~BaseWithPureVdtor() = 0;
};
''';
class B {
extend base: Cpp.A;
class DerivedWithVdtor {
extend base: Cpp.BaseWithPureVdtor;
}
inline Cpp '''
Carbon::B b;
Carbon::DerivedWithVdtor b;
''';
@@ -15,13 +15,13 @@ library "[[@TEST_NAME]]";
import Cpp;
class A {
class StaticMembers {
fn F() {}
}
inline Cpp '''
void G() {
Carbon::A::F();
void CallStaticMember() {
Carbon::StaticMembers::F();
}
''';
@@ -30,16 +30,16 @@ library "[[@TEST_NAME]]";
import Cpp;
class A {
class B {
class C {
class OuterA {
class InnerB {
class NestedC {
}
}
}
inline Cpp '''
void G() {
Carbon::A::B::C *p = nullptr;
void TestNested() {
Carbon::OuterA::InnerB::NestedC *nested_p = nullptr;
}
''';
@@ -48,10 +48,10 @@ library "[[@TEST_NAME]]";
import Cpp;
class A;
class IncompleteA;
inline Cpp '''
Carbon::A *p = nullptr;
Carbon::IncompleteA *incomplete_p = nullptr;
''';
// --- fail_incomplete_concrete.carbon
@@ -60,20 +60,20 @@ library "[[@TEST_NAME]]";
import Cpp;
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+4]]:1: error: class was forward declared here [ClassForwardDeclaredHere]
// CHECK:STDERR: class A;
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR: class IncompleteConcreteA;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
class A;
class IncompleteConcreteA;
inline Cpp '''
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+7]]:11: error: variable has incomplete type 'Carbon::A' [CppInteropParseError]
// CHECK:STDERR: 19 | Carbon::A a;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE-6]]:8: note: forward declaration of 'Carbon::A' [CppInteropParseNote]
// CHECK:STDERR: 9 | class A;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE+7]]:29: error: variable has incomplete type 'Carbon::IncompleteConcreteA' [CppInteropParseError]
// CHECK:STDERR: 19 | Carbon::IncompleteConcreteA incomplete_concrete_a;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_incomplete_concrete.carbon:[[@LINE-6]]:26: note: forward declaration of 'Carbon::IncompleteConcreteA' [CppInteropParseNote]
// CHECK:STDERR: 9 | class IncompleteConcreteA;
// CHECK:STDERR: | ^
// CHECK:STDERR:
Carbon::A a;
Carbon::IncompleteConcreteA incomplete_concrete_a;
''';
// --- fail_todo_monomorphization_failure.carbon
@@ -14,14 +14,14 @@
library "[[@TEST_NAME]]";
import Cpp;
class A {
class TwoIntFields {
var x: i32;
var y: i32;
}
inline Cpp '''
void F() {
Carbon::A a;
void AccessTwoFields() {
Carbon::TwoIntFields a;
a.x = 12;
a.y = 34;
}
@@ -31,18 +31,18 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
base class A {
base class BaseWithField {
var x: i32;
}
class B {
extend base: A;
class DerivedWithField {
extend base: BaseWithField;
var y: i32;
}
inline Cpp '''
void F() {
Carbon::B b;
void AccessInheritedField() {
Carbon::DerivedWithField b;
b.x = 12;
b.y = 34;
}
@@ -70,17 +70,17 @@ void g() {
library "[[@TEST_NAME]]";
import Cpp;
class A {}
class EmptyClass {}
inline Cpp '''
void F() {
Carbon::A a;
// CHECK:STDERR: fail_nonexistent_field.carbon:[[@LINE+4]]:5: error: no member named 'x' in 'Carbon::A' [CppInteropParseError]
void AccessNonexistentField() {
Carbon::EmptyClass a;
// CHECK:STDERR: fail_nonexistent_field.carbon:[[@LINE+4]]:5: error: no member named 'x' in 'Carbon::EmptyClass' [CppInteropParseError]
// CHECK:STDERR: 13 | a.x = 12;
// CHECK:STDERR: | ~ ^
// CHECK:STDERR:
a.x = 12;
// CHECK:STDERR: fail_nonexistent_field.carbon:[[@LINE+4]]:5: error: no member named 'y' in 'Carbon::A' [CppInteropParseError]
// CHECK:STDERR: fail_nonexistent_field.carbon:[[@LINE+4]]:5: error: no member named 'y' in 'Carbon::EmptyClass' [CppInteropParseError]
// CHECK:STDERR: 18 | a.y = 34;
// CHECK:STDERR: | ~ ^
// CHECK:STDERR:
@@ -92,7 +92,7 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class A {
class UnsupportedFieldType {
// CHECK:STDERR: fail_unsupported_field_type.carbon:[[@LINE+4]]:7: error: semantics TODO: `failed to map Carbon type to C++` [SemanticsTodo]
// CHECK:STDERR: var x: ();
// CHECK:STDERR: ^~~~~
@@ -106,14 +106,14 @@ class A {
}
inline Cpp '''
void F() {
Carbon::A a;
// CHECK:STDERR: fail_unsupported_field_type.carbon:[[@LINE+4]]:5: error: no member named 'x' in 'Carbon::A' [CppInteropParseError]
void AccessUnsupportedField() {
Carbon::UnsupportedFieldType a;
// CHECK:STDERR: fail_unsupported_field_type.carbon:[[@LINE+4]]:5: error: no member named 'x' in 'Carbon::UnsupportedFieldType' [CppInteropParseError]
// CHECK:STDERR: 24 | a.x;
// CHECK:STDERR: | ~ ^
// CHECK:STDERR:
a.x;
// CHECK:STDERR: fail_unsupported_field_type.carbon:[[@LINE+4]]:5: error: no member named 'y' in 'Carbon::A' [CppInteropParseError]
// CHECK:STDERR: fail_unsupported_field_type.carbon:[[@LINE+4]]:5: error: no member named 'y' in 'Carbon::UnsupportedFieldType' [CppInteropParseError]
// CHECK:STDERR: 29 | a.y;
// CHECK:STDERR: | ~ ^
// CHECK:STDERR:
@@ -125,14 +125,14 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class A {
class AdaptedClass {
adapt ();
}
inline Cpp '''
void F() {
Carbon::A a;
// CHECK:STDERR: fail_adapter.carbon:[[@LINE+4]]:5: error: no member named 'x' in 'Carbon::A' [CppInteropParseError]
void AccessAdaptedField() {
Carbon::AdaptedClass a;
// CHECK:STDERR: fail_adapter.carbon:[[@LINE+4]]:5: error: no member named 'x' in 'Carbon::AdaptedClass' [CppInteropParseError]
// CHECK:STDERR: 15 | a.x = 12;
// CHECK:STDERR: | ~ ^
// CHECK:STDERR:
@@ -145,7 +145,7 @@ library "[[@TEST_NAME]]";
import Cpp;
// This should not cause a crash.
class A {
class InvalidBaseClass {
// CHECK:STDERR: fail_invalid.carbon:[[@LINE+4]]:16: error: name `Whoops` not found [NameNotFound]
// CHECK:STDERR: extend base: Whoops;
// CHECK:STDERR: ^~~~~~
@@ -154,15 +154,15 @@ class A {
}
inline Cpp '''
Carbon::A x;
Carbon::InvalidBaseClass invalid_x;
''';
// --- fail_private_field.carbon
library "[[@TEST_NAME]]";
import Cpp;
class C {
fn Make() -> C {
class ClassWithPrivateField {
fn Make() -> ClassWithPrivateField {
return {.x = 123};
}
@@ -170,9 +170,9 @@ class C {
}
inline Cpp '''
int F() {
auto c = Carbon::C::Make();
// CHECK:STDERR: fail_private_field.carbon:[[@LINE+7]]:12: error: 'x' is a private member of 'Carbon::C' [CppInteropParseError]
int AccessPrivateField() {
auto c = Carbon::ClassWithPrivateField::Make();
// CHECK:STDERR: fail_private_field.carbon:[[@LINE+7]]:12: error: 'x' is a private member of 'Carbon::ClassWithPrivateField' [CppInteropParseError]
// CHECK:STDERR: 22 | return c.x;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_private_field.carbon:[[@LINE-9]]:16: note: implicitly declared private here [CppInteropParseNote]
@@ -14,13 +14,13 @@
library "[[@TEST_NAME]]";
import Cpp;
class C(T: type) {
class GenericClass(T: type) {
var t: T;
}
inline Cpp '''
void F() {
Carbon::C<int> c;
void FGeneric() {
Carbon::GenericClass<int> c;
c.t = 123;
}
''';
@@ -29,14 +29,14 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C(T: type) {
class SpecificClass(T: type) {
var t: T;
}
alias A = C(i32);
alias AliasInt = SpecificClass(i32);
inline Cpp '''
void F() {
Carbon::A a;
void FSpecific() {
Carbon::AliasInt a;
a.t = 123;
}
''';
@@ -46,25 +46,25 @@ library "[[@TEST_NAME]]";
import Cpp;
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+4]]:1: error: semantics TODO: `failed to map specific type arg to C++` [SemanticsTodo]
// CHECK:STDERR: class C(T: type) {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
// CHECK:STDERR: class UnsupportedClass(T: type) {
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
class C(T: type) {
class UnsupportedClass(T: type) {
var t: T;
}
alias A = C(());
alias AliasEmptyTuple = UnsupportedClass(());
inline Cpp '''
void F() {
void FUnsupported() {
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+8]]:11: error: semantics TODO: `interop with unsupported type` [SemanticsTodo]
// CHECK:STDERR: Carbon::A a;
// CHECK:STDERR: Carbon::AliasEmptyTuple a;
// CHECK:STDERR: ^
// CHECK:STDERR:
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+4]]:11: error: no type named 'A' in namespace 'Carbon' [CppInteropParseError]
// CHECK:STDERR: 23 | Carbon::A a;
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+4]]:11: error: no type named 'AliasEmptyTuple' in namespace 'Carbon' [CppInteropParseError]
// CHECK:STDERR: 23 | Carbon::AliasEmptyTuple a;
// CHECK:STDERR: | ~~~~~~~~^
// CHECK:STDERR:
Carbon::A a;
Carbon::AliasEmptyTuple a;
a.t = 123;
}
''';
@@ -73,7 +73,7 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C(T: type) {
class ClassWithMethod(T: type) {
// CHECK:STDERR: fail_todo_generic_class_method_call.carbon:[[@LINE+4]]:3: error: semantics TODO: `non-class non-namespace name scope` [SemanticsTodo]
// CHECK:STDERR: fn M(unused ref self) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
@@ -82,9 +82,9 @@ class C(T: type) {
}
inline Cpp '''
void F() {
Carbon::C<int> c;
// CHECK:STDERR: fail_todo_generic_class_method_call.carbon:[[@LINE+4]]:5: error: no member named 'M' in 'Carbon::C<int>' [CppInteropParseError]
void FMethodCall() {
Carbon::ClassWithMethod<int> c;
// CHECK:STDERR: fail_todo_generic_class_method_call.carbon:[[@LINE+4]]:5: error: no member named 'M' in 'Carbon::ClassWithMethod<int>' [CppInteropParseError]
// CHECK:STDERR: 19 | c.M();
// CHECK:STDERR: | ~ ^
// CHECK:STDERR:
@@ -15,15 +15,15 @@ library "[[@TEST_NAME]]";
import Cpp;
class C {
class ThreeInts {
var a: i32;
var b: i32;
var c: i32;
}
inline Cpp '''c++
static_assert(sizeof(Carbon::C) == 12);
static_assert(alignof(Carbon::C) == 4);
static_assert(sizeof(Carbon::ThreeInts) == 12);
static_assert(alignof(Carbon::ThreeInts) == 4);
''';
// --- packed.carbon
@@ -31,19 +31,19 @@ library "[[@TEST_NAME]]";
import Cpp;
class C {
class PointerInt {
var a: i32*;
var b: i32;
}
class D {
var c: C;
class PointerIntInt {
var c: PointerInt;
var d: i32;
}
inline Cpp '''c++
static_assert(sizeof(Carbon::C) == 12);
static_assert(alignof(Carbon::C) == 8);
static_assert(sizeof(Carbon::D) == 16);
static_assert(alignof(Carbon::D) == 8);
static_assert(sizeof(Carbon::PointerInt) == 12);
static_assert(alignof(Carbon::PointerInt) == 8);
static_assert(sizeof(Carbon::PointerIntInt) == 16);
static_assert(alignof(Carbon::PointerIntInt) == 8);
''';
@@ -14,13 +14,13 @@
library "[[@TEST_NAME]]";
import Cpp;
class C {
class StaticMethodClass {
fn M();
}
inline Cpp '''
void F() {
Carbon::C::M();
void StaticMethod() {
Carbon::StaticMethodClass::M();
}
''';
@@ -28,13 +28,13 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class MethodLValueClass {
fn M(self);
}
inline Cpp '''
void F() {
Carbon::C c;
void MethodLValue() {
Carbon::MethodLValueClass c;
c.M();
}
''';
@@ -43,13 +43,13 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class MethodRValueClass {
fn M(self);
}
inline Cpp '''
void F() {
Carbon::C().M();
void MethodRValue() {
Carbon::MethodRValueClass().M();
}
''';
@@ -57,12 +57,12 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class MethodConstLValueClass {
fn M(self);
}
inline Cpp '''
void F(const Carbon::C& c) {
void MethodConstLValue(const Carbon::MethodConstLValueClass& c) {
c.M();
}
''';
@@ -71,13 +71,13 @@ void F(const Carbon::C& c) {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class RefMethodLValueClass {
fn M(ref self);
}
inline Cpp '''
void F() {
Carbon::C c;
void RefMethodLValue() {
Carbon::RefMethodLValueClass c;
c.M();
}
''';
@@ -86,20 +86,20 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class RefMethodRValueClass {
fn M(ref self);
}
inline Cpp '''
void F() {
void RefMethodRValue() {
// CHECK:STDERR: fail_ref_method_rvalue.carbon:[[@LINE+7]]:3: error: 'this' argument to member function 'M' is an rvalue, but function has non-const lvalue ref-qualifier [CppInteropParseError]
// CHECK:STDERR: 17 | Carbon::C().M();
// CHECK:STDERR: 17 | Carbon::RefMethodRValueClass().M();
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_ref_method_rvalue.carbon:[[@LINE-8]]:17: note: 'M' declared here [CppInteropParseNote]
// CHECK:STDERR: 5 | fn M(ref self);
// CHECK:STDERR: | ^
// CHECK:STDERR:
Carbon::C().M();
Carbon::RefMethodRValueClass().M();
}
''';
@@ -107,13 +107,13 @@ void F() {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class RefMethodConstLValueClass {
fn M(ref self);
}
inline Cpp '''
void F(const Carbon::C& c) {
// CHECK:STDERR: fail_ref_method_const_lvalue.carbon:[[@LINE+7]]:3: error: 'this' argument to member function 'M' has type 'const Carbon::C', but function is not marked const [CppInteropParseError]
void RefMethodConstLValue(const Carbon::RefMethodConstLValueClass& c) {
// CHECK:STDERR: fail_ref_method_const_lvalue.carbon:[[@LINE+7]]:3: error: 'this' argument to member function 'M' has type 'const Carbon::RefMethodConstLValueClass', but function is not marked const [CppInteropParseError]
// CHECK:STDERR: 17 | c.M();
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_ref_method_const_lvalue.carbon:[[@LINE-8]]:17: note: 'M' declared here [CppInteropParseNote]
@@ -14,13 +14,13 @@
library "[[@TEST_NAME]]";
import Cpp;
class C {
class PublicClass {
static var x: i32 = 123;
}
inline Cpp '''
int F() {
return Carbon::C::x;
int PublicStatic() {
return Carbon::PublicClass::x;
}
''';
@@ -28,19 +28,19 @@ int F() {
library "[[@TEST_NAME]]";
import Cpp;
class C {
class PrivateClass {
private static var x: i32 = 123;
}
inline Cpp '''
int F() {
// CHECK:STDERR: fail_static_private.carbon:[[@LINE+7]]:21: error: 'x' is a private member of 'Carbon::C' [CppInteropParseError]
// CHECK:STDERR: 17 | return Carbon::C::x;
// CHECK:STDERR: | ^
int PrivateStatic() {
// CHECK:STDERR: fail_static_private.carbon:[[@LINE+7]]:32: error: 'x' is a private member of 'Carbon::PrivateClass' [CppInteropParseError]
// CHECK:STDERR: 17 | return Carbon::PrivateClass::x;
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_static_private.carbon:[[@LINE-8]]:23: note: implicitly declared private here [CppInteropParseNote]
// CHECK:STDERR: 5 | private static var x: i32 = 123;
// CHECK:STDERR: | ^
// CHECK:STDERR:
return Carbon::C::x;
return Carbon::PrivateClass::x;
}
''';