diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ba9de1ac98de08..0982a18e462998 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -250,6 +250,9 @@ Improvements to Clang's diagnostics such as attempting to call ``free`` on an unallocated object. Fixes `#79443 `_. +- The ``XXX parameter of 'main' must be of type`` error can now be disabled via ``-Wno-main``. + `#85494 `_. + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8e97902564af08..6cf4e288af5f1f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -950,9 +950,9 @@ def err_main_surplus_args : Error<"too many parameters (%0) for 'main': " "must be 0, 2, or 3">; def warn_main_one_arg : Warning<"only one parameter on 'main' declaration">, InGroup
; -def err_main_arg_wrong : Error<"%select{first|second|third|fourth}0 " +def warn_main_arg_wrong : Warning<"%select{first|second|third|fourth}0 " "parameter of 'main' (%select{argument count|argument array|environment|" - "platform-specific data}0) must be of type %1">; + "platform-specific data}0) must be of type %1">, DefaultError, InGroup
; def warn_main_returns_bool_literal : Warning<"bool literal returned from " "'main'">, InGroup
; def err_main_global_variable : diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5850cd0ab6b9aa..2718934609842b 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12488,7 +12488,7 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) { } if (mismatch) { - Diag(FD->getLocation(), diag::err_main_arg_wrong) << i << Expected[i]; + Diag(FD->getLocation(), diag::warn_main_arg_wrong) << i << Expected[i]; // TODO: suggest replacing given type with expected type FD->setInvalidDecl(true); } diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp index 42e87e5431f2a5..135c828e7366a0 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp @@ -4,6 +4,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST4 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST5 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST6 +// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST6A -Wno-main // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST7 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST8 @@ -64,6 +65,16 @@ main( // expected-error {{first parameter of 'main' (argument count) must be of const int main(); // expected-error {{'main' must return 'int'}} +#elif TEST6A + +void // expected-error {{'main' must return 'int'}} +main( + float a +) { +} + +const int main(); // expected-error {{'main' must return 'int'}} + #elif TEST7 // expected-no-diagnostics