Fix PR2790 by making a warning an EXTWARN instead of EXTENSION.
Add a new EXTENSION warning for "return (some void expression);"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61187
91177308-0d34-0410-b5e6-
96231b3b80d8
"non-void %select{function|method}1 %0 should return a value")
DIAG(ext_return_missing_expr, EXTENSION,
"non-void %select{function|method}1 %0 should return a value")
-DIAG(ext_return_has_expr, EXTENSION,
+DIAG(ext_return_has_expr, EXTWARN,
"void %select{function|method}1 %0 should not return a value")
+DIAG(ext_return_has_void_expr, EXTENSION,
+ "void %select{function|method}1 %0 should not return void expression")
DIAG(err_shufflevector_non_vector, ERROR,
"first two arguments to __builtin_shufflevector must be vectors")
if (FnRetType->isVoidType()) {
if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns)
- if (FunctionDecl *FD = getCurFunctionDecl())
- Diag(ReturnLoc, diag::ext_return_has_expr)
- << FD->getIdentifier() << 0/*function*/<< RetValExp->getSourceRange();
- else
- Diag(ReturnLoc, diag::ext_return_has_expr)
- << getCurMethodDecl()->getDeclName() << 1 /*method*/
- << RetValExp->getSourceRange();
+ unsigned D = diag::ext_return_has_expr;
+ if (RetValExp->getType()->isVoidType())
+ D = diag::ext_return_has_void_expr;
+ NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
+
+ Diag(ReturnLoc, D)
+ << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
+ << RetValExp->getSourceRange();
}
return new ReturnStmt(ReturnLoc, RetValExp);
}
@try {
// Do something
} @catch (...) {}
- return 0;
+ return;
}
+++ /dev/null
-// RUN: clang %s -fsyntax-only -verify -pedantic
-// PR2790
-
-void f1() {
- return 0; // expected-warning {{void function 'f1' should not return a value}}
-}
-
-int f2() {
- return; // expected-warning {{non-void function 'f2' should return a value}}
-}
// PR3208
void t12(int) {} // expected-error{{parameter name omitted}}
+// PR2790
+void t13() {
+ return 0; // expected-warning {{void function 't13' should not return a value}}
+}
+int t14() {
+ return; // expected-warning {{non-void function 't14' should return a value}}
+}
int32_t compCount = 0;
if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-note {{previous implicit declaration is here}}
}
- return ((void *)0);
+ return ((void *)0); // expected-warning {{void function 'func' should not return a value}}
}
Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error{{conflicting types for '_CFCalendarDecomposeAbsoluteTimeV'}}
return 0;