]> granicus.if.org Git - clang/commitdiff
Always treat 'main' as an extern "C" function, so that we detect
authorDouglas Gregor <dgregor@apple.com>
Thu, 21 Oct 2010 16:57:46 +0000 (16:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 21 Oct 2010 16:57:46 +0000 (16:57 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117029 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp
test/CXX/basic/basic.start/basic.start.main/p2h.cpp [new file with mode: 0644]

index 9008b346c92a094bfe363f1ef256f6b21fc73d74..87d2a9f81f8b22f4ee9e3aabd137f238bee8cd38 100644 (file)
@@ -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">;
index 108353f53b0053fba35994cd77c2deca68f73c7f..7670316b9d7d2a44d936ffee54bc999a0bbe6039 100644 (file)
@@ -964,7 +964,7 @@ public:
     Ovl_NonFunction
   };
   OverloadKind CheckOverload(Scope *S,
-                             FunctionDecl *New,
+                             FunctionDecl *New, 
                              const LookupResult &OldDecls,
                              NamedDecl *&OldDecl,
                              bool IsForUsingDecl);
index 4898d6f2fc0cde23b404e9b51ea7795d2bb0579d..5a1edbd0e6710d1ffc2f8c04872621812a59ea8c 100644 (file)
@@ -1001,7 +1001,7 @@ bool FunctionDecl::isExternC() const {
       break;
   }
 
-  return false;
+  return isMain();
 }
 
 bool FunctionDecl::isGlobal() const {
index 57cbb46480b0f9a70260e338a80c64acf546646a..f1045d3c0b7aa60dc6fc98369d1db2068e4cd39b 100644 (file)
@@ -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 (file)
index 0000000..abf8faa
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s 
+
+template<typename T>
+int main() { } // expected-error{{'main' cannot be a template}}
+