<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - for Microsoft compatibility, #include <corecrt> from stddef.h etc"
   href="https://bugs.llvm.org/show_bug.cgi?id=40789">40789</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>for Microsoft compatibility, #include <corecrt> from stddef.h etc
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mib.bugzilla@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have received a dll from a 3rd party along with a header file. The .h file
compiles OK with the Microsoft compiler, but it fails with clang. This is
because the clang compiler uses a different version of stddef.h than the
Microsoft compiler. The Microsoft version brings in e.g. <corecrt.h> which
introduces a lot of names including Microsoft's <sal.h> file.

Of course I can add a #include to make the compile successful, but I'd like to
know if you would consider allowing modifications to the clang version so that
that change isn't necessary.

I could preprocess all the clang headers to find the other headers that should
be brought in.  Microsoft headers are pretty complex so it's not immediately
obvious which #include's to include, for example their headers accomodate the
"RC" compiler, I assume we wouldn't want the includes specific to RC to be
added.

Here's an example,
clang -c struct.cpp
struct.cpp:9:31: error: unknown type name '_Out_opt_cap_'
 virtual int   QueryLastError(_Out_opt_cap_(cbErrMax) char szError[cbErrMax]) ;
                              ^
struct.cpp:9:55: error: expected ')'
 virtual int   QueryLastError(_Out_opt_cap_(cbErrMax) char szError[cbErrMax]) ;
                                                      ^
struct.cpp:9:30: note: to match this '('
 virtual int   QueryLastError(_Out_opt_cap_(cbErrMax) char szError[cbErrMax]) ;
                             ^
2 errors generated.
ksh-3.2$ cat struct.cpp
// interface for error reporting
#include <stddef.h>
enum Report_Consts {
    cbErrMax     = 1024,
};
typedef struct Report_Error {
 virtual int   QueryLastError(_Out_opt_cap_(cbErrMax) char szError[cbErrMax])
};
#endif
Report_Error; 

Would you consider allowing changes like this,
diff --git a/lib/Headers/stddef.h b/lib/Headers/stddef.h
index 7354996711..686a79168d 100644
--- a/lib/Headers/stddef.h
+++ b/lib/Headers/stddef.h
@@ -34,6 +34,11 @@
 #if !__has_feature(modules)
 #define __STDDEF_H
 #endif

+#if defined(_MSC_VER)
+#include <corecrt.h>
+#endif // defined(_MSC_VER)

--Melanie Blower
(I work for Intel on the C++ compiler)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>