[llvm-bugs] [Bug 40789] New: for Microsoft compatibility, #include <corecrt> from stddef.h etc

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 20 08:42:52 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40789

            Bug ID: 40789
           Summary: for Microsoft compatibility, #include <corecrt> from
                    stddef.h etc
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mib.bugzilla at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190220/40da2f33/attachment.html>


More information about the llvm-bugs mailing list