PR 20146
authorNathan Sidwell <nathan@acm.org>
Thu, 15 Jan 2015 16:45:53 +0000 (16:45 +0000)
committerNathan Sidwell <nathan@acm.org>
Thu, 15 Jan 2015 16:45:53 +0000 (16:45 +0000)
reject CV void return type on C definitions per 6.9.1/3

llvm-svn: 226178

clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/Sema/function.c

index 8966c55..9e3393e 100644 (file)
@@ -4320,6 +4320,8 @@ def note_exits_block_captures_strong : Note<
 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 0f96a1c..7116973 100644 (file)
@@ -2792,8 +2792,16 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
       // 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 81d303c..4404b52 100644 (file)
@@ -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'}}
+{
+}