summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2013-01-21 11:25:03 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2013-01-21 11:25:03 +0000
commit7ec6f3ddeb4cd7168b9efb6f0a950e852c292a56 (patch)
treef30b217180b6821d1574498514a41196f6e1e9dc
parent9b46312c87561f0e7fe286de5d7341a139bee067 (diff)
downloadbcm5719-llvm-7ec6f3ddeb4cd7168b9efb6f0a950e852c292a56.tar.gz
bcm5719-llvm-7ec6f3ddeb4cd7168b9efb6f0a950e852c292a56.zip
Add a fixit for _Noreturn main,
add tests for fixits removing static and inline from main llvm-svn: 173024
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td1
-rw-r--r--clang/lib/Sema/SemaDecl.cpp10
-rw-r--r--clang/test/Sema/warn-main.c32
3 files changed, 41 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3999fadc517..3b37658abba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -390,6 +390,7 @@ 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 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">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 7936efa136d..f73ea9875a5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6474,8 +6474,14 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
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());
diff --git a/clang/test/Sema/warn-main.c b/clang/test/Sema/warn-main.c
new file mode 100644
index 00000000000..ecff32096d6
--- /dev/null
+++ b/clang/test/Sema/warn-main.c
@@ -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@+1 2{{previous definition is here}}
+int main() {
+ return 0;
+}
+
+// expected-error@+2 {{static declaration of 'main' follows non-static declaration}}
+// expected-warning@+1 {{'main' should not be declared static}}
+static int main() {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:8}:""
+ return 0;
+}
+
+// expected-error@+3 {{redefinition of 'main'}}
+// expected-error@+2 {{'main' is not allowed to be declared inline}}
+// expected-note@+1 {{previous definition is here}}
+inline int main() {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:8}:""
+ return 0;
+}
+
+// expected-error@+3 {{redefinition of 'main'}}
+// expected-warning@+2 {{'main' is not allowed to be declared _Noreturn}}
+// expected-note@+1 {{remove '_Noreturn'}}
+_Noreturn int main() {
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:11}:""
+ return 0;
+}
+
OpenPOWER on IntegriCloud