Author: nathan
Date: Thu Jan 15 10:45:53 2015
New Revision: 226178

URL: http://llvm.org/viewvc/llvm-project?rev=226178&view=rev
Log:
PR 20146
reject CV void return type on C definitions per 6.9.1/3

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/function.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=226178&r1=226177&r2=226178&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 15 10:45:53 
2015
@@ -4320,6 +4320,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">;

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=226178&r1=226177&r2=226178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jan 15 10:45:53 2015
@@ -2792,8 +2792,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

Modified: cfe/trunk/test/Sema/function.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=226178&r1=226177&r2=226178&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Thu Jan 15 10:45:53 2015
@@ -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'}}
+{
+}


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to