mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Work around MSVC's __cplusplus regarding C++11
This commit is contained in:
1 parent
635b502649
commit
cb19841358
4 files changed
+68
-58
No files matched your search
@@ -32,9 +32,14 @@
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus >= 201103L
|
||||
// MSVC before Visual Studio 2017 mis-reported the __cplusplus level:
|
||||
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
// We just assume that ifdef __cplusplus, MSVC implies C++11 or later. Note
|
||||
// that MSVC doesn't support "#warning" and Clang also defines __GNUC__.
|
||||
#if (__cplusplus >= 201103L) || defined(_MSC_VER)
|
||||
#define WUFFS_HAS_CPP11
|
||||
#include <memory>
|
||||
#else
|
||||
#elif defined(__GNUC__)
|
||||
#warning "Wuffs' C++ code requires -std=c++11 or later"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -406,7 +406,7 @@ func insertInterfaceDeclarations(buf *buffer) error {
|
||||
buf.writes(" } private_impl;\n\n")
|
||||
|
||||
buf.writes("#ifdef __cplusplus\n")
|
||||
buf.writes("#if __cplusplus >= 201103L\n")
|
||||
buf.writes("#if defined(WUFFS_HAS_CPP11)\n")
|
||||
buf.printf(" using unique_ptr = std::unique_ptr<wuffs_base__%s, decltype(&free)>;\n", n)
|
||||
buf.writes("#endif\n\n")
|
||||
|
||||
@@ -1161,7 +1161,7 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
|
||||
fullStructName := g.pkgPrefix + structName + "__struct"
|
||||
b.writes("#ifdef __cplusplus\n")
|
||||
|
||||
b.writes("#if __cplusplus >= 201103L\n")
|
||||
b.writes("#if defined(WUFFS_HAS_CPP11)\n")
|
||||
b.printf("using unique_ptr = std::unique_ptr<%s%s, decltype(&free)>;\n\n", g.pkgPrefix, structName)
|
||||
b.writes("// On failure, the alloc_etc functions return nullptr. They don't throw.\n\n")
|
||||
b.writes("static inline unique_ptr\n")
|
||||
@@ -1177,9 +1177,9 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
|
||||
iName, g.pkgPrefix, structName, iName)
|
||||
b.printf("}\n")
|
||||
}
|
||||
b.writes("#endif // __cplusplus >= 201103L\n\n")
|
||||
b.writes("#endif // defined(WUFFS_HAS_CPP11)\n\n")
|
||||
|
||||
b.writes("#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)\n")
|
||||
b.writes("#if defined(WUFFS_HAS_CPP11) && !defined(WUFFS_IMPLEMENTATION)\n")
|
||||
b.writes("// Disallow constructing or copying an object via standard C++ mechanisms,\n")
|
||||
b.writes("// e.g. the \"new\" operator, as this struct is intentionally opaque. Its total\n")
|
||||
b.writes("// size and field layout is not part of the public, stable, memory-safe API.\n")
|
||||
@@ -1204,7 +1204,7 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
|
||||
b.writes("// different, so that passing the latter will be rejected by the initialize\n")
|
||||
b.writes("// function, we add an arbitrary amount of dead weight.\n")
|
||||
b.writes("uint8_t dead_weight[123000000]; // 123 MB.\n")
|
||||
b.writes("#endif // (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)\n\n")
|
||||
b.writes("#endif // defined(WUFFS_HAS_CPP11) && !defined(WUFFS_IMPLEMENTATION)\n\n")
|
||||
|
||||
b.writes("inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT\n" +
|
||||
"initialize(\nsize_t sizeof_star_self,\nuint64_t wuffs_version,\nuint32_t initialize_flags) {\n")
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package data
|
||||
|
||||
const BaseAllImplC = "" +
|
||||
"#ifndef WUFFS_INCLUDE_GUARD__BASE\n#define WUFFS_INCLUDE_GUARD__BASE\n\n#if defined(WUFFS_IMPLEMENTATION) && !defined(WUFFS_CONFIG__MODULES)\n#define WUFFS_CONFIG__MODULES\n#define WUFFS_CONFIG__MODULE__BASE\n#endif\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING ABOVE.\n\n// !! INSERT base/copyright\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include <string.h>\n\n#ifdef __cplusplus\n#if __cplusplus >= 201103L\n#include <memory>\n#else\n#warning \"Wuffs' C++ code requires -std=c++11 or later\"\n#endif\n\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-public.h.\n\n// !! INSERT InterfaceDeclarations.\n\n" +
|
||||
"#ifndef WUFFS_INCLUDE_GUARD__BASE\n#define WUFFS_INCLUDE_GUARD__BASE\n\n#if defined(WUFFS_IMPLEMENTATION) && !defined(WUFFS_CONFIG__MODULES)\n#define WUFFS_CONFIG__MODULES\n#define WUFFS_CONFIG__MODULE__BASE\n#endif\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING ABOVE.\n\n// !! INSERT base/copyright\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include <string.h>\n\n#ifdef __cplusplus\n// MSVC before Visual Studio 2017 mis-reported the __cplusplus level:\n// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/\n// We just assume that ifdef __cplusplus, MSVC implies C++11 or later. Note\n// that MSVC doesn't support \"#warning\" and Clang also defines __GNUC__.\n#if (__cplusplus >= 201103L) || defined(_MSC_VER)\n#define WUFFS_HAS_CPP11\n#include <memory>\n#elif defined(__GNUC__)\n#warning \"Wuffs' C++ code requires -std=c++11 or later\"\n#endif\n\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-public.h.\n\n// !! INSERT InterfaceDeclarations.\n\n" +
|
||||
"" +
|
||||
"// ----------------\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n// WUFFS C HEADER ENDS HERE.\n#ifdef WUFFS_IMPLEMENTATION\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-private.h.\n\n" +
|
||||
"" +
|
||||
|
||||
Reference in new issue
Block a user