Diagnose variadic main() as an extension; addresses PR17905.
authorAaron Ballman <aaron@aaronballman.com>
Thu, 23 Apr 2015 16:12:42 +0000 (16:12 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 23 Apr 2015 16:12:42 +0000 (16:12 +0000)
llvm-svn: 235605

clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-main.c

index d7b5718..b44aa37 100644 (file)
@@ -485,6 +485,8 @@ def warn_static_main : Warning<"'main' should not be declared static">,
     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'">;
index 5bb39cb..6916710 100644 (file)
@@ -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.
index 58a6dfd..4620663 100644 (file)
@@ -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; }