[PATCH] Add Microsoft's handling of exception specifications

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Add Microsoft's handling of exception specifications

Martin Vejnár
Hi,

I'm attaching a patch that adds an option -fms-except-spec that makes sema
treat exception specifications with at least one type-id as if the
exception specification was missing. In other words,

    void foo() throw(...);
    void foo() throw(std::bad_alloc);

will now parse without errors if -fms-except-spec is given. This in turn
makes it possible to parse sources that include Microsoft's <new> header.

I'm very new to clang, sorry if I've missed something. Best regards,
--
Martin

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

ms-except-spec.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Add Microsoft's handling of exception specifications

Francois Pichet
I don't think it is necessary to add a MsExceptSpec flag in
LangOptions nor a -fms-except-spec compiler switch.
Simply add the following test for MSVC compatibility:
  if (getLangOptions().Microsoft)

Because if we add an option or switch for every microsoft extension,
it is never going to end.

On Tue, Aug 24, 2010 at 5:18 AM, Martin Vejnár <[hidden email]> wrote:

> Hi,
>
> I'm attaching a patch that adds an option -fms-except-spec that makes sema
> treat exception specifications with at least one type-id as if the
> exception specification was missing. In other words,
>
>    void foo() throw(...);
>    void foo() throw(std::bad_alloc);
>
> will now parse without errors if -fms-except-spec is given. This in turn
> makes it possible to parse sources that include Microsoft's <new> header.
>
> I'm very new to clang, sorry if I've missed something. Best regards,
> --
> Martin
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Add Microsoft's handling of exception specifications

Martin Vejnár
On Tue, 24 Aug 2010 05:51:10 -0400, Francois Pichet <[hidden email]>
wrote:
> I don't think it is necessary to add a MsExceptSpec flag in
> LangOptions nor a -fms-except-spec compiler switch.
> Simply add the following test for MSVC compatibility:
>   if (getLangOptions().Microsoft)
>
> Because if we add an option or switch for every microsoft extension,
> it is never going to end.

That was my original thought as well, however, the mistreatment of
exception specifications is not strictly speaking an extension. I can
imagine a situation where we would want to support MS extensions and yet
deal with exception specifications correctly.

In any case, I'm attaching another patch that does what you suggest.

Best regards,
--
Martin

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

ms-except-spec-noopt.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Add Microsoft's handling of exception specifications

Douglas Gregor

On Aug 24, 2010, at 3:19 AM, Martin Vejnár wrote:

> On Tue, 24 Aug 2010 05:51:10 -0400, Francois Pichet <[hidden email]>
> wrote:
>> I don't think it is necessary to add a MsExceptSpec flag in
>> LangOptions nor a -fms-except-spec compiler switch.
>> Simply add the following test for MSVC compatibility:
>>  if (getLangOptions().Microsoft)
>>
>> Because if we add an option or switch for every microsoft extension,
>> it is never going to end.
>
> That was my original thought as well, however, the mistreatment of
> exception specifications is not strictly speaking an extension. I can
> imagine a situation where we would want to support MS extensions and yet
> deal with exception specifications correctly.
>
> In any case, I'm attaching another patch that does what you suggest.

I think the patch is okay, but please provide test cases that explore how Visual C++ actually checks compatibility of exception specifications, to make sure that we're modeling what Visual C++ does rather than having some different non-conforming behavior.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Add Microsoft's handling of exception specifications

Martin Vejnár
On 8/26/2010 4:42 PM, Douglas Gregor wrote:
> On Aug 24, 2010, at 3:19 AM, Martin Vejnár wrote:
>> In any case, I'm attaching another patch that does what you suggest.
>
> I think the patch is okay, but please provide test cases that explore
> how Visual C++ actually checks compatibility of exception
> specifications, to make sure that we're modeling what Visual C++ does
> rather than having some different non-conforming behavior.

I've added a simple test case to the patch. Note that the patch is not
trying to replicate the exact behavior of MSVC with respect to exception
specifications, it only addresses the particular case that causes clang
to fail on Microsoft's <new>.

In particular, the patch keeps the following code ill-formed:

     void (*q)() throw(int) = 0;
     void (*p)() throw(float) = q;

whereas MSVC accepts it.
--
Martin

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

ms-except-spec-noopt.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Add Microsoft's handling of exception specifications

Douglas Gregor

On Aug 28, 2010, at 4:30 AM, Martin Vejnár wrote:

> On 8/26/2010 4:42 PM, Douglas Gregor wrote:
>> On Aug 24, 2010, at 3:19 AM, Martin Vejnár wrote:
>>> In any case, I'm attaching another patch that does what you suggest.
>>
>> I think the patch is okay, but please provide test cases that explore
>> how Visual C++ actually checks compatibility of exception
>> specifications, to make sure that we're modeling what Visual C++ does
>> rather than having some different non-conforming behavior.
>
> I've added a simple test case to the patch. Note that the patch is not trying to replicate the exact behavior of MSVC with respect to exception specifications, it only addresses the particular case that causes clang to fail on Microsoft's <new>.
>
> In particular, the patch keeps the following code ill-formed:
>
>    void (*q)() throw(int) = 0;
>    void (*p)() throw(float) = q;
>
> whereas MSVC accepts it.

Okay. Note that your patch broke the test in test/SemaCXX/exception-spec.cpp. I've fixed up the test (by moving the Microsoft-specific bits to a different test), but in the future, please be sure that the Clang test suite runs cleanly with your patch. Committed the result as r112482. Thanks!

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev