]> granicus.if.org Git - clang/commitdiff
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)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235605 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d7b571888cc116832017e7fbd762d292fceab6f5..b44aa37b9ec5ef50e6792568ba4bf89020195da4 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 5bb39cbf1474a985a5481e04904f74345b7a106d..6916710036cdc0960018c2fba51cc44760824126 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 58a6dfde108da90b706b7ebb5dc3a601795e9c5e..4620663037e2379d66a3f2edbb73f9143ba92f05 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; }