r193044 - Sema: Diagnose global replacement functions declared as inline

David Majnemer david.majnemer at gmail.com
Sun Oct 20 17:33:09 PDT 2013


Good point, I've committed a similar change in r193061. I decided to go
with 'replacement function' instead of 'non-placement' seeing as how
placement-new isn't a replacement function.

Thanks!



On Sun, Oct 20, 2013 at 11:43 AM, Richard Smith <richard at metafoo.co.uk>wrote:

> The diagnostic wording is a little imprecise. Maybe "non-placement
> 'operator whatever' cannot ..."?
> On 19 Oct 2013 22:45, "David Majnemer" <david.majnemer at gmail.com> wrote:
>
>> Author: majnemer
>> Date: Sun Oct 20 00:40:29 2013
>> New Revision: 193044
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=193044&view=rev
>> Log:
>> Sema: Diagnose global replacement functions declared as inline
>>
>> This fixes PR17591.
>>
>> N.B. This actually goes beyond what the standard mandates by requiring
>> the restriction to hold for declarations instead of definitions.  This
>> is believed to be a defect in the standard and an LWG issue has been
>> submitted.
>>
>> Modified:
>>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>     cfe/trunk/lib/Sema/SemaDecl.cpp
>>     cfe/trunk/test/SemaCXX/new-delete.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=193044&r1=193043&r2=193044&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Oct 20
>> 00:40:29 2013
>> @@ -5900,6 +5900,8 @@ def err_operator_new_delete_declared_in_
>>    "%0 cannot be declared inside a namespace">;
>>  def err_operator_new_delete_declared_static : Error<
>>    "%0 cannot be declared static in global scope">;
>> +def err_operator_new_delete_declared_inline : Error<
>> +  "%0 cannot be declared 'inline'">;
>>  def err_operator_new_delete_invalid_result_type : Error<
>>    "%0 must return type %1">;
>>  def err_operator_new_delete_dependent_result_type : Error<
>>
>> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=193044&r1=193043&r2=193044&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 20 00:40:29 2013
>> @@ -6804,6 +6804,13 @@ Sema::ActOnFunctionDeclarator(Scope *S,
>>        NewFD->setType(Context.getFunctionType(FPT->getResultType(),
>>                                               FPT->getArgTypes(), EPI));
>>      }
>> +
>> +    // C++11 [replacement.functions]p3:
>> +    //  The program's definitions shall not be specified as inline.
>> +    if (isInline && NewFD->isReplaceableGlobalAllocationFunction())
>> +      Diag(D.getDeclSpec().getInlineSpecLoc(),
>> +           diag::err_operator_new_delete_declared_inline)
>> +        << NewFD->getDeclName();
>>    }
>>
>>    // Filter out previous declarations that don't match the scope.
>>
>> Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=193044&r1=193043&r2=193044&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/new-delete.cpp Sun Oct 20 00:40:29 2013
>> @@ -24,6 +24,8 @@ void* operator new(size_t, int*); // exp
>>  void* operator new(size_t, float*); // expected-note 3 {{candidate}}
>>  void* operator new(size_t, S); // expected-note 2 {{candidate}}
>>
>> +inline void operator delete(void *); // expected-error {{'operator
>> delete' cannot be declared 'inline'}}
>> +
>>  struct foo { };
>>
>>  void good_news()
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131020/a8c76c8f/attachment.html>


More information about the cfe-commits mailing list