[cfe-commits] r173024 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/warn-main.c

Dmitri Gribenko gribozavr at gmail.com
Mon Jan 21 03:25:03 PST 2013


Author: gribozavr
Date: Mon Jan 21 05:25:03 2013
New Revision: 173024

URL: http://llvm.org/viewvc/llvm-project?rev=173024&view=rev
Log:
Add a fixit for _Noreturn main,
add tests for fixits removing static and inline from main

Added:
    cfe/trunk/test/Sema/warn-main.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    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=173024&r1=173023&r2=173024&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 21 05:25:03 2013
@@ -390,6 +390,7 @@
 def err_inline_main : Error<"'main' is not allowed to be declared inline">;
 def ext_noreturn_main : ExtWarn<
   "'main' is not allowed to be declared _Noreturn">, InGroup<Main>;
+def note_main_remove_noreturn : Note<"remove '_Noreturn'">;
 def err_constexpr_main : Error<
   "'main' is not allowed to be declared constexpr">;
 def err_main_template_decl : Error<"'main' cannot be a template">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173024&r1=173023&r2=173024&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 21 05:25:03 2013
@@ -6474,8 +6474,14 @@
   if (FD->isInlineSpecified())
     Diag(DS.getInlineSpecLoc(), diag::err_inline_main) 
       << FixItHint::CreateRemoval(DS.getInlineSpecLoc());
-  if (DS.isNoreturnSpecified())
-    Diag(DS.getNoreturnSpecLoc(), diag::ext_noreturn_main);
+  if (DS.isNoreturnSpecified()) {
+    SourceLocation NoreturnLoc = DS.getNoreturnSpecLoc();
+    SourceRange NoreturnRange(NoreturnLoc,
+                              PP.getLocForEndOfToken(NoreturnLoc));
+    Diag(NoreturnLoc, diag::ext_noreturn_main);
+    Diag(NoreturnLoc, diag::note_main_remove_noreturn)
+      << FixItHint::CreateRemoval(NoreturnRange);
+  }
   if (FD->isConstexpr()) {
     Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_main)
       << FixItHint::CreateRemoval(DS.getConstexprSpecLoc());

Added: cfe/trunk/test/Sema/warn-main.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-main.c?rev=173024&view=auto
==============================================================================
--- cfe/trunk/test/Sema/warn-main.c (added)
+++ cfe/trunk/test/Sema/warn-main.c Mon Jan 21 05:25:03 2013
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s
+
+// expected-note at +1 2{{previous definition is here}}
+int main() {
+  return 0;
+}
+
+// expected-error at +2 {{static declaration of 'main' follows non-static declaration}}
+// expected-warning at +1 {{'main' should not be declared static}}
+static int main() {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:8}:""
+  return 0;
+}
+
+// expected-error at +3 {{redefinition of 'main'}}
+// expected-error at +2 {{'main' is not allowed to be declared inline}}
+// expected-note at +1 {{previous definition is here}}
+inline int main() {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:8}:""
+  return 0;
+}
+
+// expected-error at +3 {{redefinition of 'main'}}
+// expected-warning at +2 {{'main' is not allowed to be declared _Noreturn}}
+// expected-note at +1 {{remove '_Noreturn'}}
+_Noreturn int main() {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:11}:""
+  return 0;
+}
+





More information about the cfe-commits mailing list