forked from OSchip/llvm-project
Always treat 'main' as an extern "C" function, so that we detect
redeclarations of main appropriately rather than allowing it to be overloaded. Also, disallowing declaring main as a template. Fixes GCC DejaGNU g++.old-deja/g++.other/main1.C. llvm-svn: 117029
This commit is contained in:
parent
096011eebf
commit
bff6203152
|
@ -229,6 +229,7 @@ def warn_unusual_main_decl : Warning<"'main' should not be declared "
|
||||||
"%select{static|inline|static or inline}0">;
|
"%select{static|inline|static or inline}0">;
|
||||||
def err_unusual_main_decl : Error<"'main' is not allowed to be declared "
|
def err_unusual_main_decl : Error<"'main' is not allowed to be declared "
|
||||||
"%select{static|inline|static or inline}0">;
|
"%select{static|inline|static or inline}0">;
|
||||||
|
def err_main_template_decl : Error<"'main' cannot be a template">;
|
||||||
def err_main_returns_nonint : Error<"'main' must return 'int'">;
|
def err_main_returns_nonint : Error<"'main' must return 'int'">;
|
||||||
def err_main_surplus_args : Error<"too many parameters (%0) for 'main': "
|
def err_main_surplus_args : Error<"too many parameters (%0) for 'main': "
|
||||||
"must be 0, 2, or 3">;
|
"must be 0, 2, or 3">;
|
||||||
|
|
|
@ -964,7 +964,7 @@ public:
|
||||||
Ovl_NonFunction
|
Ovl_NonFunction
|
||||||
};
|
};
|
||||||
OverloadKind CheckOverload(Scope *S,
|
OverloadKind CheckOverload(Scope *S,
|
||||||
FunctionDecl *New,
|
FunctionDecl *New,
|
||||||
const LookupResult &OldDecls,
|
const LookupResult &OldDecls,
|
||||||
NamedDecl *&OldDecl,
|
NamedDecl *&OldDecl,
|
||||||
bool IsForUsingDecl);
|
bool IsForUsingDecl);
|
||||||
|
|
|
@ -1001,7 +1001,7 @@ bool FunctionDecl::isExternC() const {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return isMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FunctionDecl::isGlobal() const {
|
bool FunctionDecl::isGlobal() const {
|
||||||
|
|
|
@ -4182,6 +4182,11 @@ void Sema::CheckMain(FunctionDecl* FD) {
|
||||||
if (nparams == 1 && !FD->isInvalidDecl()) {
|
if (nparams == 1 && !FD->isInvalidDecl()) {
|
||||||
Diag(FD->getLocation(), diag::warn_main_one_arg);
|
Diag(FD->getLocation(), diag::warn_main_one_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
|
||||||
|
Diag(FD->getLocation(), diag::err_main_template_decl);
|
||||||
|
FD->setInvalidDecl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
|
bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int main() { } // expected-error{{'main' cannot be a template}}
|
||||||
|
|
Loading…
Reference in New Issue