]> granicus.if.org Git - clang/commitdiff
Disallow constexpr main.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 4 Feb 2012 06:10:17 +0000 (06:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 4 Feb 2012 06:10:17 +0000 (06:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149770 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8f5e2c7e6b3c65a0ee65bbf1293a604faec74419..ab724b53c46c24e9f2e3d680c1fc2e6e9e7b9b1b 100644 (file)
@@ -330,6 +330,8 @@ def warn_static_main : Warning<"'main' should not be declared static">,
     InGroup<Main>;
 def err_static_main : Error<"'main' is not allowed to be declared static">;
 def err_inline_main : Error<"'main' is not allowed to be declared inline">;
+def err_constexpr_main : Error<
+  "'main' is not allowed to be declared constexpr">;
 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': "
index f6f97dddbcaeb646556c158963abd6f84d435924..0e5e6781a68e16cca4690b47fc6f143b77dd1dcb 100644 (file)
@@ -5778,8 +5778,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
 }
 
 void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
-  // C++ [basic.start.main]p3:  A program that declares main to be inline
-  //   or static is ill-formed.
+  // C++11 [basic.start.main]p3:  A program that declares main to be inline,
+  //   static or constexpr is ill-formed.
   // C99 6.7.4p4:  In a hosted environment, the inline function specifier
   //   shall not appear in a declaration of main.
   // static main is not an error under C99, but we should warn about it.
@@ -5790,6 +5790,11 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
   if (FD->isInlineSpecified())
     Diag(DS.getInlineSpecLoc(), diag::err_inline_main) 
       << FixItHint::CreateRemoval(DS.getInlineSpecLoc());
+  if (FD->isConstexpr()) {
+    Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_main)
+      << FixItHint::CreateRemoval(DS.getConstexprSpecLoc());
+    FD->setConstexpr(false);
+  }
 
   QualType T = FD->getType();
   assert(T->isFunctionType() && "function decl is not of function type");
diff --git a/test/CXX/basic/basic.start/basic.start.main/p2i.cpp b/test/CXX/basic/basic.start/basic.start.main/p2i.cpp
new file mode 100644 (file)
index 0000000..db8da3c
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ %s -std=c++11 -fsyntax-only -verify
+// RUN: not %clang_cc1 -x c++ %t -std=c++11 -fixit
+// RUN: %clang_cc1 -x c++ %t -std=c++11 -fsyntax-only
+
+constexpr int main() { } // expected-error{{'main' is not allowed to be declared constexpr}}