def err_main_arg_wrong : Error<"%select{first|second|third|fourth}0 "
"parameter of 'main' (%select{argument count|argument array|environment|"
"platform-specific data}0) must be of type %1">;
+def warn_main_returns_bool_literal : Warning<"bool literal returned from "
+ "'main'">, InGroup<Main>;
def err_main_global_variable :
Error<"main cannot be declared as global variable">;
def warn_main_redefined : Warning<"variable named 'main' with external linkage "
if (FD->isNoReturn())
Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
<< FD->getDeclName();
+ if (FD->isMain() && RetValExp)
+ if (isa<CXXBoolLiteralExpr>(RetValExp))
+ Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
+ << RetValExp->getSourceRange();
} else if (ObjCMethodDecl *MD = getCurMethodDecl()) {
FnRetType = MD->getReturnType();
isObjCMethod = true;
--- /dev/null
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wmain -verify %s
+
+// expected-note@+1 {{previous definition is here}}
+int main() {
+ return 0;
+} // no-warning
+
+// expected-error@+1 {{redefinition of 'main'}}
+int main() {
+ return 1.0;
+} // no-warning
+
+int main() {
+ bool b = true;
+ return b; // no-warning
+}
+
+int main() {
+ return true; // expected-warning {{bool literal returned from 'main'}}
+}