From: Aaron Ballman Date: Thu, 23 Apr 2015 16:12:42 +0000 (+0000) Subject: Diagnose variadic main() as an extension; addresses PR17905. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f92f076224213a7c26ff96e4b36accb27b212a6d;p=clang Diagnose variadic main() as an extension; addresses PR17905. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235605 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index d7b571888c..b44aa37b9e 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -485,6 +485,8 @@ def warn_static_main : Warning<"'main' should not be declared static">, InGroup
; 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
; def ext_noreturn_main : ExtWarn< "'main' is not allowed to be declared _Noreturn">, InGroup
; def note_main_remove_noreturn : Note<"remove '_Noreturn'">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5bb39cbf14..6916710036 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8252,6 +8252,12 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) { 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. diff --git a/test/Sema/warn-main.c b/test/Sema/warn-main.c index 58a6dfde10..4620663037 100644 --- a/test/Sema/warn-main.c +++ b/test/Sema/warn-main.c @@ -29,3 +29,5 @@ _Noreturn int main() { return 0; } +// expected-warning@+1 {{'main' is not allowed to be declared variadic}} +int main(int argc, char**argv, ...) { return 0; }