[cfe-commits] r117029 - in /cfe/trunk: 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

Douglas Gregor dgregor at apple.com
Thu Oct 21 09:57:46 PDT 2010


Author: dgregor
Date: Thu Oct 21 11:57:46 2010
New Revision: 117029

URL: http://llvm.org/viewvc/llvm-project?rev=117029&view=rev
Log:
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.

Added:
    cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp   (with props)
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=117029&r1=117028&r2=117029&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 21 11:57:46 2010
@@ -229,6 +229,7 @@
     "%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">;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=117029&r1=117028&r2=117029&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Oct 21 11:57:46 2010
@@ -964,7 +964,7 @@
     Ovl_NonFunction
   };
   OverloadKind CheckOverload(Scope *S,
-                             FunctionDecl *New,
+                             FunctionDecl *New, 
                              const LookupResult &OldDecls,
                              NamedDecl *&OldDecl,
                              bool IsForUsingDecl);

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=117029&r1=117028&r2=117029&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Oct 21 11:57:46 2010
@@ -1001,7 +1001,7 @@
       break;
   }
 
-  return false;
+  return isMain();
 }
 
 bool FunctionDecl::isGlobal() const {

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=117029&r1=117028&r2=117029&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 21 11:57:46 2010
@@ -4182,6 +4182,11 @@
   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) {

Added: cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp?rev=117029&view=auto
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp (added)
+++ cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp Thu Oct 21 11:57:46 2010
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s 
+
+template<typename T>
+int main() { } // expected-error{{'main' cannot be a template}}
+

Propchange: cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CXX/basic/basic.start/basic.start.main/p2h.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list