diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 1 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | test/CXX/basic/basic.start/basic.start.main/p2h.cpp | 5 |
5 files changed, 13 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9008b346c9..87d2a9f81f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -229,6 +229,7 @@ def warn_unusual_main_decl : Warning<"'main' should not be declared " "%select{static|inline|static or inline}0">; def err_unusual_main_decl : Error<"'main' is not allowed to be declared " "%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_surplus_args : Error<"too many parameters (%0) for 'main': " "must be 0, 2, or 3">; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 108353f53b..7670316b9d 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -964,7 +964,7 @@ public: Ovl_NonFunction }; OverloadKind CheckOverload(Scope *S, - FunctionDecl *New, + FunctionDecl *New, const LookupResult &OldDecls, NamedDecl *&OldDecl, bool IsForUsingDecl); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 4898d6f2fc..5a1edbd0e6 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1001,7 +1001,7 @@ bool FunctionDecl::isExternC() const { break; } - return false; + return isMain(); } bool FunctionDecl::isGlobal() const { diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 57cbb46480..f1045d3c0b 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4182,6 +4182,11 @@ void Sema::CheckMain(FunctionDecl* FD) { if (nparams == 1 && !FD->isInvalidDecl()) { 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) { diff --git a/test/CXX/basic/basic.start/basic.start.main/p2h.cpp b/test/CXX/basic/basic.start/basic.start.main/p2h.cpp new file mode 100644 index 0000000000..abf8faa968 --- /dev/null +++ b/test/CXX/basic/basic.start/basic.start.main/p2h.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template<typename T> +int main() { } // expected-error{{'main' cannot be a template}} + |