[PATCH] [RFC] PR20146 - Cannot return void with qualifiers

Zach Davis zdavkeos at gmail.com
Mon Jul 7 09:22:03 PDT 2014


Thanks for the comments.  I have:

- Cleaned up the code
- Made the warning an error
- Moved the check into diagnoseIgnoredFunctionQualifiers()
- Added 3 test cases to test/Sema/function.c



On Thu, Jul 3, 2014 at 4:41 PM, Alp Toker <alp at nuanti.com> wrote:
>
> On 03/07/2014 22:08, Zach Davis wrote:
>>
>> As reported in bug 20146, a function cannot have a return type of
>> 'void' with qualifiers.
>>
>> Clang does emit a warning that the qualifiers are ignored
>> [-Wignored-qualifiers] (off by default), but according to [1] this
>> code is non-conforming.
>>
>> The attached patch makes Clang issue a more specific warning like so:
>>
>>      test3.c:8:18: warning: return type of void cannot be qualified
>> 'volatile void'
>>      volatile void baz(void) { return; }
>>                    ^
>>
>> [1]http://www.open-std.org/jtc1/sc22/wg14/docs/rr/dr_113.html
>
>
> It seems fine to make this a hard error instead of a warning for C, and
> probably C++ too. Richard?
>
>>
>> 20146_return_qual_void.patch
>>
>>
>> Index: lib/Sema/SemaType.cpp
>> ===================================================================
>> --- lib/Sema/SemaType.cpp       (revision 212275)
>> +++ lib/Sema/SemaType.cpp       (working copy)
>> @@ -2741,6 +2741,15 @@
>>           D.setInvalidType(true);
>>         }
>>   +      // C99 6.9.1/3: The return type of a function shall be void or
>> +      // an object type other than array type.
>> +      // A return type of void cannot be qualified.
>> +      if (T->isVoidType() && T.getCVRQualifiers()) {
>> +          unsigned diagID = diag::warn_func_returning_qualified_void;
>
>
> Just pass the ID directly to Diag().
>
>> +          S.Diag(DeclType.Loc, diagID) << T;
>> +          D.setInvalidType(true);
>> +      }
>> +
>
>
> How about placing this check with an early return at the top of
> diagnoseIgnoredFunctionQualifiers()?
>
>>         // Do not allow returning half FP value.
>>         // FIXME: This really should be in BuildFunctionType.
>>         if (T->isHalfType()) {
>> Index: include/clang/Basic/DiagnosticSemaKinds.td
>> ===================================================================
>> --- include/clang/Basic/DiagnosticSemaKinds.td  (revision 212275)
>> +++ include/clang/Basic/DiagnosticSemaKinds.td  (working copy)
>> @@ -4160,6 +4160,8 @@
>>     def err_func_returning_array_function : Error<
>>     "function cannot return %select{array|function}0 type %1">;
>> +def warn_func_returning_qualified_void : Warning<
>> +  "return type of void cannot be qualified %0">;
>
>
> (Warnings need to have a diagnostic group / -W flag, though it doesn't
> matter if you go ahead and make it an error.)
>
>>   def err_field_declared_as_function : Error<"field %0 declared as a
>> function">;
>>   def err_field_incomplete : Error<"field has incomplete type %0">;
>>   def ext_variable_sized_type_in_struct : ExtWarn<
>
>
> Test case?
>
> Alp.
>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
> --
> http://www.nuanti.com
> the browser experts
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20146_return_qual_void_2.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140707/93993b7c/attachment.bin>


More information about the cfe-commits mailing list