This patch fixes a really pedantic error reported as 20146 http://llvm.org/bugs/show_bug.cgi?id=20146

Apparently in C a void function definition cannot use a qualified void return.type. c99 [6.9.1]/3 says:

The return type of a function shall be void or an object type other than array 
type.

There appears no such restriction on a function declaration. (6.9.1 is explicitly about a function definition)

C++ appears explicitly bless it in c++ 03 [6.6.3]/3 says:

A return statement with an expression of type “cv void” can be
> used only in functions with a return type of cv void; the expression
> is evaluated just before the function returns to its caller.


OK?

nathan
# svn diff src
# svn diff src/projects/compiler-rt
# svn diff src/tools/clang
Index: src/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- src/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td	(revision 224048)
+++ src/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -4315,6 +4315,8 @@ def note_exits_block_captures_strong : N
 def note_exits_block_captures_weak : Note<
   "jump exits lifetime of block which weakly captures a variable">;
 
+def err_func_returning_qualified_void : Error<
+  "function cannot return qualified void type %0">;
 def err_func_returning_array_function : Error<
   "function cannot return %select{array|function}0 type %1">;
 def err_field_declared_as_function : Error<"field %0 declared as a function">;
Index: src/tools/clang/lib/Sema/SemaType.cpp
===================================================================
--- src/tools/clang/lib/Sema/SemaType.cpp	(revision 224048)
+++ src/tools/clang/lib/Sema/SemaType.cpp	(working copy)
@@ -2791,8 +2791,16 @@ static TypeSourceInfo *GetFullTypeForDec
       // class type in C++.
       if ((T.getCVRQualifiers() || T->isAtomicType()) &&
           !(S.getLangOpts().CPlusPlus &&
-            (T->isDependentType() || T->isRecordType())))
-        diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
+            (T->isDependentType() || T->isRecordType()))) {
+	if (T->isVoidType() && !S.getLangOpts().CPlusPlus &&
+	    D.getFunctionDefinitionKind () == FDK_Definition) {
+	  // [6.9.1/3] qualified void return is invalid on a C
+	  // function definition.  Apparently ok on declarations and
+	  // in C++ though (!)
+	  S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T;
+	} else
+	  diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
+      }
 
       // Objective-C ARC ownership qualifiers are ignored on the function
       // return type (by type canonicalization). Complain if this attribute
Index: src/tools/clang/test/Sema/function.c
===================================================================
--- src/tools/clang/test/Sema/function.c	(revision 224048)
+++ src/tools/clang/test/Sema/function.c	(working copy)
@@ -113,3 +113,9 @@ void t22(int *ptr, int (*array)[3]) {
   decays(array);
   no_decay(array);
 }
+
+void const Bar (void); // ok on decl
+// PR 20146
+void const Bar (void) // expected-error {{function cannot return qualified void type 'const void'}}
+{
+}
# svn diff src/tools/clang/tools/extra
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to