Add a fixit for _Noreturn main,

add tests for fixits removing static and inline from main

llvm-svn: 173024
This commit is contained in:
Dmitri Gribenko 2013-01-21 11:25:03 +00:00
parent 9b46312c87
commit 7ec6f3ddeb
3 changed files with 41 additions and 2 deletions

View File

@ -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">;

View File

@ -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());

View File

@ -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;
}