Files
swift-mirror/test/Interop/Cxx/class/Inputs/mutability-annotations.h

57 lines
2.0 KiB
C

#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_MUTABILITY_ANNOTATIONS_H
#define TEST_INTEROP_CXX_CLASS_INPUTS_MUTABILITY_ANNOTATIONS_H
struct HasConstMethodAnnotatedAsMutating {
int a;
int annotatedMutating() const __attribute__((__swift_attr__("mutating"))) {
const_cast<HasConstMethodAnnotatedAsMutating *>(this)->a++;
return a;
}
int annotatedMutatingWithOtherAttrs() const __attribute__((__swift_attr__("public"))) __attribute__((__swift_attr__("mutating"))) {
const_cast<HasConstMethodAnnotatedAsMutating *>(this)->a++;
return a;
}
};
struct HasMutableProperty {
mutable int a;
int b;
int annotatedNonMutating() const __attribute__((__swift_attr__("nonmutating"))) {
return b;
}
int noAnnotation() const { return b; }
// expected-error@+3 {{multiple conflicting annotations found on 'contradictingAnnotations'}}
// expected-note@+2 {{'nonmutating' annotation found here}}
// expected-note@+1 {{SWIFT_MUTATING annotation found here}}
int contradictingAnnotations() const __attribute__((__swift_attr__("nonmutating"))) __attribute__((__swift_attr__("mutating"))) {
return b;
}
// expected-error@+3 {{multiple 'nonmutating' annotations found on 'duplicateAnnotations'}}
// expected-note@+2 {{'nonmutating' annotation found here}}
// expected-note@+1 {{'nonmutating' annotation found here}}
int duplicateAnnotations() const __attribute__((__swift_attr__("nonmutating"))) __attribute__((__swift_attr__("nonmutating"))) {
return b;
}
};
struct NoMutableProperty {
int a;
// expected-warning@+1 {{attribute 'nonmutating' has no effect without any mutable fields}}
int isConst() const __attribute__((__swift_attr__("nonmutating"))) {
return a;
}
// expected-warning@+2 {{attribute 'nonmutating' has no effect without any mutable fields}}
// expected-warning@+1 {{attribute 'nonmutating' has no effect on non-const method}}
int nonConst() __attribute__((__swift_attr__("nonmutating"))) { return a; }
};
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_MUTABILITY_ANNOTATIONS_H