def err_unusual_main_decl : Error<"'main' is not allowed to be declared "
"%select{static|inline|static or inline}0">;
def err_main_returns_nonint : Error<"'main' must return 'int'">;
-def err_main_surplus_args : Error<"%0 is too many arguments for 'main': "
+def err_main_surplus_args : Error<"too many parameters (%0) for 'main': "
"must be 0, 2, or 3">;
-def warn_main_one_arg : Warning<"one-argument 'main' is usually a mistake">;
-def err_main_arg_wrong : Error<"%select{first|second|third}0 argument of "
- "'main' should be of type %1">;
+def warn_main_one_arg : Warning<"only one parameter on 'main' declaration">;
+def err_main_arg_wrong : Error<"%select{first|second|third|fourth}0 "
+ "parameter of 'main' (%select{argument count|argument array|environment|"
+ "platform-specific data}0) must be of type %1">;
/// parser diagnostics
def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">;
#include "clang/Lex/HeaderSearch.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Triple.h"
#include <algorithm>
#include <cstring>
#include <functional>
unsigned nparams = FTP->getNumArgs();
assert(FD->getNumParams() == nparams);
- if (nparams > 3) {
+ bool HasExtraParameters = (nparams > 3);
+
+ // Darwin passes an undocumented fourth argument of type char**. If
+ // other platforms start sprouting these, the logic below will start
+ // getting shifty.
+ if (nparams == 4 &&
+ Context.Target.getTriple().getOS() == llvm::Triple::Darwin)
+ HasExtraParameters = false;
+
+ if (HasExtraParameters) {
Diag(FD->getLocation(), diag::err_main_surplus_args) << nparams;
FD->setInvalidDecl(true);
nparams = 3;
QualType CharPP =
Context.getPointerType(Context.getPointerType(Context.CharTy));
- QualType Expected[] = { Context.IntTy, CharPP, CharPP };
+ QualType Expected[] = { Context.IntTy, CharPP, CharPP, CharPP };
for (unsigned i = 0; i < nparams; ++i) {
QualType AT = FTP->getArgType(i);
// RUN: %clang_cc1 -fsyntax-only -verify %s
void // expected-error {{error: 'main' must return 'int'}}
-main( // expected-error {{error: first argument of 'main' should be of type 'int'}}
+main( // expected-error {{error: first parameter of 'main' (argument count) must be of type 'int'}}
float a
) {
}