forked from OSchip/llvm-project
Add a fixit for _Noreturn main,
add tests for fixits removing static and inline from main llvm-svn: 173024
This commit is contained in:
parent
9b46312c87
commit
7ec6f3ddeb
|
@ -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">;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue