r235605 - Diagnose variadic main() as an extension; addresses PR17905.
Aaron Ballman
aaron at aaronballman.com
Thu Apr 23 09:12:42 PDT 2015
Author: aaronballman
Date: Thu Apr 23 11:12:42 2015
New Revision: 235605
URL: http://llvm.org/viewvc/llvm-project?rev=235605&view=rev
Log:
Diagnose variadic main() as an extension; addresses PR17905.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/warn-main.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=235605&r1=235604&r2=235605&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 23 11:12:42 2015
@@ -485,6 +485,8 @@ def warn_static_main : Warning<"'main' s
InGroup<Main>;
def err_static_main : Error<"'main' is not allowed to be declared static">;
def err_inline_main : Error<"'main' is not allowed to be declared inline">;
+def ext_variadic_main : ExtWarn<
+ "'main' is not allowed to be declared variadic">, InGroup<Main>;
def ext_noreturn_main : ExtWarn<
"'main' is not allowed to be declared _Noreturn">, InGroup<Main>;
def note_main_remove_noreturn : Note<"remove '_Noreturn'">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=235605&r1=235604&r2=235605&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr 23 11:12:42 2015
@@ -8252,6 +8252,12 @@ void Sema::CheckMain(FunctionDecl* FD, c
bool HasExtraParameters = (nparams > 3);
+ if (FTP->isVariadic()) {
+ Diag(FD->getLocation(), diag::ext_variadic_main);
+ // FIXME: if we had information about the location of the ellipsis, we
+ // could add a FixIt hint to remove it as a parameter.
+ }
+
// Darwin passes an undocumented fourth argument of type char**. If
// other platforms start sprouting these, the logic below will start
// getting shifty.
Modified: cfe/trunk/test/Sema/warn-main.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-main.c?rev=235605&r1=235604&r2=235605&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-main.c (original)
+++ cfe/trunk/test/Sema/warn-main.c Thu Apr 23 11:12:42 2015
@@ -29,3 +29,5 @@ _Noreturn int main() {
return 0;
}
+// expected-warning at +1 {{'main' is not allowed to be declared variadic}}
+int main(int argc, char**argv, ...) { return 0; }
More information about the cfe-commits
mailing list