[PATCH] Add Microsoft's handling of exception specifications

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,

ms-except-spec.patch (3.1 KB)

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,

ms-except-spec-noopt.patch (764 Bytes)

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

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.

ms-except-spec-noopt.patch (1.4 KB)

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