void taskmain(int argc, char* argv);
void taskmain() {
printf(“libtask”);
}
Hello,
for the above code, gcc reports error and clang -std=gnu89 keeps quiet.
is this intentional?
Regards,
Afriza N. Arief
void taskmain(int argc, char* argv);
void taskmain() {
printf(“libtask”);
}
Hello,
for the above code, gcc reports error and clang -std=gnu89 keeps quiet.
is this intentional?
Regards,
Afriza N. Arief
Not intentional... we really ought to be at least printing a warning
here. Please file at http://llvm.org/bugs/ .
(Sorry about the delayed response.)
-Eli
Thank you, filed at http://llvm.org/bugs/show_bug.cgi?id=12414
Any pointers roughly where in the code this can fixed?
Regards,
Arief
Try Sema::MergeFunctionDecl in SemaDecl.cpp .
-Eli
Hello,
The way gcc handles the number of parameters is strange:
(1)
void abc(int a);
void abc() {}
int main() {}
=> gcc produces:
af.c: In function ‘abc’:
af.c:2:1: error: number of arguments doesn’t match prototype
af.c:1:6: error: prototype declaration
=> clang compiles successfully. the attached patch changes this to a warning
(2)
void abc();
void abc(int a) {}
int main() {}
=> gcc compiles successfully!
=> clang compiles successfully
(3) for both
(3a)
void abc(int a, int b);
void abc(int a) {}
int main() {}
(3b)
void abc(int a);
void abc(int a, int b) {}
int main() {}
=> gcc produces
af.c:2:6: error: conflicting types for ‘abc’
af.c:1:6: note: previous declaration of ‘abc’ was here
=> clang produces
af.c:2:6: error: conflicting types for 'abc'
void abc(int a) {}
^
af.c:1:6: note: previous declaration is here
void abc(int a, int b);
^
1 error generated.
And so, here is my first attempt
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td
b/include/clang/Basic/DiagnosticSemaKinds.td
index 30173fb..7ab3a9b 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -181,6 +181,10 @@ def ext_implicit_function_decl : ExtWarn<
InGroup<ImplicitFunctionDeclare>;
def note_function_suggestion : Note<"did you mean %0?">;
+def warn_prototype_args_mismatch : Warning<
+ "GCC does not allow function definition to have different number "
+ "of arguments than the prototype">, InGroup<GccCompat>;
The way gcc handles the number of parameters is strange:
(1)
void abc(int a);
void abc() {}
int main() {}
=> gcc produces:
af.c: In function ‘abc’:
af.c:2:1: error: number of arguments doesn’t match prototype
af.c:1:6: error: prototype declaration
=> clang compiles successfully. the attached patch changes this to a warning
Please keep in mind that for C, the second mode does not specify a
function with 0 arguments. It's K&R style for a variadic function.
As such, it is incorrect to talk about "number of arguments".
(2)
void abc();
void abc(int a) {}
int main() {}
=> gcc compiles successfully!
=> clang compiles successfully
This is just as bogus and should create at least a warning.
Joerg