Skip to content

Commit 4e4c511

Browse files
committed
[Import as error] Error on non-prototyped function declarations
1 parent a87e668 commit 4e4c511

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ ERROR(swift_name_protocol_static, none, "swift_name cannot be used to define "
6363
"%select{static member|init}0 on "
6464
"protocol",
6565
(bool))
66+
ERROR(swift_name_no_prototype, none,
67+
"swift_name cannot be used on a non-prototyped function declaration", ())
6668

6769
WARNING(inconsistent_swift_name,none,
6870
"inconsistent Swift name for Objective-C %select{method|property}0 "

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,8 +2344,16 @@ namespace {
23442344
return nullptr;
23452345
}
23462346

2347+
if (!decl->hasPrototype()) {
2348+
// FIXME: source location...
2349+
Impl.SwiftContext.Diags.diagnose({}, diag::swift_name_no_prototype);
2350+
Impl.SwiftContext.Diags.diagnose({}, diag::note_while_importing,
2351+
decl->getName());
2352+
return nullptr;
2353+
}
2354+
23472355
bool allowNSUIntegerAsInt =
2348-
Impl.shouldAllowNSUIntegerAsInt(isInSystemModule(dc), decl);
2356+
Impl.shouldAllowNSUIntegerAsInt(isInSystemModule(dc), decl);
23492357

23502358
auto &SwiftCtx = Impl.SwiftContext;
23512359
SourceLoc noLoc{};

test/IDE/Inputs/custom-modules/ImportAsMember.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern int IAMStruct1StaticGetProperty(void)
4646
__attribute__((swift_name("getter:Struct1.property()")));
4747
extern int IAMStruct1StaticSetProperty(int i)
4848
__attribute__((swift_name("setter:Struct1.property(i:)")));
49-
extern int IAMStruct1StaticGetOnlyProperty()
49+
extern int IAMStruct1StaticGetOnlyProperty(void)
5050
__attribute__((swift_name("getter:Struct1.getOnlyProperty()")));
5151

5252
extern void IAMStruct1SelfComesLast(double x, struct IAMStruct1 s)

test/IDE/Inputs/custom-modules/InferImportAsMember.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,38 @@ extern void IAMStruct1SetNonPropertyNoGet(struct IAMStruct1 s, double x);
5151

5252
/// Various static functions that can't quite be imported as properties.
5353
// Too many parameters
54-
extern float IAMStruct1StaticGetNonPropertyNumParams();
54+
extern float IAMStruct1StaticGetNonPropertyNumParams(void);
5555
extern void IAMStruct1StaticSetNonPropertyNumParams(float a,
5656
float b);
5757
extern void IAMStruct1StaticGetNonPropertyNumParamsGetter(double d);
5858

5959
// Set type doesn't match get type
60-
extern float IAMStruct1StaticGetNonPropertyType();
60+
extern float IAMStruct1StaticGetNonPropertyType(void);
6161
extern void IAMStruct1StaticSetNonPropertyType(double x);
6262

6363
// Didn't find self on setter
64-
extern float IAMStruct1StaticGetNonPropertyNoSelf();
64+
extern float IAMStruct1StaticGetNonPropertyNoSelf(void);
6565
extern void IAMStruct1StaticSetNonPropertyNoSelf(double x, double y);
6666

6767
// No set only properties
6868
extern void IAMStruct1StaticSetNonPropertyNoGet(double x);
6969

7070
/// Static method
71-
extern double IAMStruct1StaticMethod();
72-
extern double IAMStruct1TLAThreeLetterAcronym();
71+
extern double IAMStruct1StaticMethod(void);
72+
extern double IAMStruct1TLAThreeLetterAcronym(void);
7373

7474
/// Static computed properties
75-
extern double IAMStruct1StaticGetProperty();
75+
extern double IAMStruct1StaticGetProperty(void);
7676
extern double IAMStruct1StaticSetProperty(double);
77-
extern double IAMStruct1StaticGetOnlyProperty();
77+
extern double IAMStruct1StaticGetOnlyProperty(void);
7878

7979
/// Omit needless words
8080
extern double IAMStruct1ONWNeedlessTypeArgLabel(double Double);
8181

8282
/// Fuzzy
83-
extern struct IAMStruct1 IAMFuzzyStruct1Create();
84-
extern struct IAMStruct1 IAMFuzzyStruct1CreateWithFuzzyName();
85-
extern struct IAMStruct1 IAMFuzzyStruct1CreateFuzzyName();
83+
extern struct IAMStruct1 IAMFuzzyStruct1Create(void);
84+
extern struct IAMStruct1 IAMFuzzyStruct1CreateWithFuzzyName(void);
85+
extern struct IAMStruct1 IAMFuzzyStruct1CreateFuzzyName(void);
8686

8787
extern double __IAMStruct1IgnoreMe(struct IAMStruct1 s);
8888

@@ -104,7 +104,7 @@ const TDStruct TDStructCreateWithFloat(float Float);
104104
typedef const struct __attribute__((objc_bridge(id))) __IAMClass *IAMClassRef;
105105
typedef IAMClassRef IAMOtherName;
106106

107-
extern unsigned IAMClassGetTypeID();
107+
extern unsigned IAMClassGetTypeID(void);
108108
extern IAMClassRef IAMClassCreate(double i);
109109
extern void IAMClassInvert(IAMOtherName iamOtherName);
110110

0 commit comments

Comments
 (0)