Add char_traits<T> specialisations for wxUniChar and NANODBC_SQLCHAR

when building on Apple with Clang >= 17.

These specialisations are not strictly required by the C++ standard,
and have been removed from LLVM.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20631
This commit is contained in:
JamesJCode 2025-04-15 20:29:09 +01:00
parent 2ee66ccfac
commit a5be581b1b
43 changed files with 303 additions and 43 deletions

View File

@ -19,7 +19,7 @@
*/
#include <magic_enum.hpp>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/log.h>
#include <wx/regex.h>
#include <wx/stdstream.h>

View File

@ -27,7 +27,7 @@
#include <kicommon.h>
#include <lib_id.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
class KICOMMON_API DESIGN_BLOCK

View File

@ -26,7 +26,7 @@
#define DIALOG_DESIGN_BLOCK_PROPERTIES_H
#include <dialogs/dialog_design_block_properties_base.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
class SCH_EDIT_FRAME;
class DESIGN_BLOCK;

View File

@ -24,7 +24,7 @@
*/
#include <map>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <gal/color4d.h>
#include <i18n_utility.h>
#include <wx/crt.h>

View File

@ -24,7 +24,7 @@
#include <ctime>
#include <boost/algorithm/string.hpp>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/base64.h>
#include <kicad_curl/kicad_curl_easy.h>

View File

@ -22,7 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <settings/parameters.h>
#include <wildcards_and_files_ext.h>

View File

@ -35,7 +35,7 @@
#include <wx/string.h>
#include <wx/arrstr.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
namespace EASYEDA
{

View File

@ -34,7 +34,7 @@
#include <wx/string.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <math/vector2d.h>

View File

@ -19,7 +19,7 @@
*/
#include <i18n_utility.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <settings/parameters.h>
#include <wildcards_and_files_ext.h>

View File

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <json_conversions.h>
// Specializations to allow directly reading/writing wxStrings from JSON

View File

@ -33,7 +33,7 @@
#include <boost/uuid/entropy_error.hpp>
#endif
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <cctype>
#include <mutex>

View File

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <project/component_class_settings.h>
#include <settings/parameters.h>

View File

@ -22,7 +22,7 @@
#include <algorithm>
#include <limits>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <project/net_settings.h>
#include <settings/parameters.h>

View File

@ -21,7 +21,7 @@
*/
#include <settings/aui_settings.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/gdicmn.h>
#include <wx/aui/framemanager.h>

View File

@ -19,7 +19,7 @@
*/
#include <settings/bom_settings.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <core/json_serializers.h>
#include <wx/translation.h>

View File

@ -19,7 +19,7 @@
*/
#include <settings/grid_settings.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/translation.h>
#include <core/json_serializers.h>

View File

@ -20,7 +20,7 @@
#include <wx/aui/framemanager.h> // ensure class wxAuiPaneInfo is defined for other includes
#include "settings/kicad_settings.h"
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <settings/aui_settings.h>
#include <settings/parameters.h>

View File

@ -20,7 +20,7 @@
#include <wx/string.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <project/project_file.h>
#include <settings/parameters.h>

View File

@ -23,7 +23,7 @@
*/
#include <magic_enum.hpp>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <tool/action_toolbar.h>
#include <tool/ui/toolbar_configuration.h>

View File

@ -30,7 +30,7 @@
#include <erc/erc.h>
#include <fstream>
#include <macros.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <rc_json_schema.h>

View File

@ -34,7 +34,7 @@
#include <core/kicad_algo.h>
#include <wx/wfstream.h>
#include <xnode.h> // also nests: <wx/xml/xml.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <project_sch.h>
#include <symbol_lib_table.h>

View File

@ -39,7 +39,7 @@
#include <tool/tool_manager.h>
#include <sch_selection_tool.h>
#include <dialogs/dialog_design_block_properties.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
bool checkOverwriteDb( wxWindow* aFrame, wxString& libname, wxString& newName )
{

View File

@ -37,7 +37,7 @@
#include <wx/stdstream.h>
#include <wx/zipstrm.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <core/map_helpers.h>
#include <wx/wfstream.h>

View File

@ -40,7 +40,7 @@
#include <wx/fs_zip.h>
#include <wx/log.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <string_utils.h>
#include <wildcards_and_files_ext.h>
#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>

View File

@ -32,7 +32,7 @@
#include <gestfich.h>
#include <kiface_base.h>
#include <macros.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <pgm_base.h>
#include <richio.h>
#include <settings/settings_manager.h>

View File

@ -26,7 +26,7 @@
* @file job_file_reader.cpp
*/
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/filename.h>
#include <wildcards_and_files_ext.h>

View File

@ -20,8 +20,137 @@
#ifndef JSON_COMMON_H
#define JSON_COMMON_H
#include <nlohmann/json.hpp>
/***********************************************************************************************************************
* If we are compiling on Apple with Clang >= 17, the version of LLVM no longer includes a generic template for
* char_traits for char types which are not specified in the C++ standard. We define our own here for types required by
* the JSON library.
*
* From: https://github.com/llvm/llvm-project/commit/c3668779c13596e223c26fbd49670d18cd638c40
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
**********************************************************************************************************************/
#ifdef __APPLE__
#if __clang_major__ >= 17
#include <wx/unichar.h>
template <>
struct std::char_traits<wxUniChar>
{
using char_type = wxUniChar;
using int_type = int;
using off_type = std::streamoff;
using pos_type = std::streampos;
using state_type = mbstate_t;
static inline void assign( char_type& __c1, const char_type& __c2 ) noexcept { __c1 = __c2; }
static inline bool eq( char_type __c1, char_type __c2 ) noexcept { return __c1 == __c2; }
static inline bool lt( char_type __c1, char_type __c2 ) noexcept { return __c1 < __c2; }
static constexpr int compare( const char_type* __s1, const char_type* __s2, size_t __n )
{
for( ; __n; --__n, ++__s1, ++__s2 )
{
if( lt( *__s1, *__s2 ) )
return -1;
if( lt( *__s2, *__s1 ) )
return 1;
}
return 0;
}
static size_t length( const char_type* __s )
{
size_t __len = 0;
for( ; !eq( *__s, char_type( 0 ) ); ++__s )
++__len;
return __len;
}
static constexpr const char_type* find( const char_type* __s, size_t __n, const char_type& __a )
{
for( ; __n; --__n )
{
if( eq( *__s, __a ) )
return __s;
++__s;
}
return nullptr;
}
static constexpr char_type* move( char_type* __s1, const char_type* __s2, size_t __n )
{
if( __n == 0 )
return __s1;
char_type* __r = __s1;
if( __s1 < __s2 )
{
for( ; __n; --__n, ++__s1, ++__s2 )
assign( *__s1, *__s2 );
}
else if( __s2 < __s1 )
{
__s1 += __n;
__s2 += __n;
for( ; __n; --__n )
assign( *--__s1, *--__s2 );
}
return __r;
}
static constexpr char_type* copy( char_type* __s1, const char_type* __s2, size_t __n )
{
char_type* __r = __s1;
for( ; __n; --__n, ++__s1, ++__s2 )
assign( *__s1, *__s2 );
return __r;
}
static char_type* assign( char_type* __s, size_t __n, char_type __a )
{
char_type* __r = __s;
for( ; __n; --__n, ++__s )
assign( *__s, __a );
return __r;
}
static inline constexpr int_type not_eof( int_type __c ) noexcept
{
return eq_int_type( __c, eof() ) ? ~eof() : __c;
}
static inline char_type to_char_type( int_type __c ) noexcept { return char_type( __c ); }
static inline int_type to_int_type( char_type __c ) noexcept { return static_cast<int_type>( __c ); }
static inline constexpr bool eq_int_type( int_type __c1, int_type __c2 ) noexcept { return __c1 == __c2; }
static inline constexpr int_type eof() noexcept { return static_cast<int_type>( EOF ); }
};
#endif
#endif
#include <nlohmann/json.hpp>
#include <kicommon.h>
/**
@ -32,4 +161,4 @@ class KICOMMON_API JSON_COMMON_EXPORT_STUB final : public nlohmann::json
{
};
#endif
#endif

View File

@ -34,7 +34,7 @@
#include <wx/filefn.h>
#include <wx/log.h>
#include <wx/filename.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wildcards_and_files_ext.h>
#define LCK "KICAD_LOCKING"

View File

@ -26,7 +26,7 @@
#include <settings/parameters.h>
// Can be removed by refactoring PARAM_LAYER_PRESET
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <math/box2.h>
#include <glm/glm.hpp>

View File

@ -20,7 +20,7 @@
#ifndef RC_JSON_SCHEMA_H
#define RC_JSON_SCHEMA_H
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/string.h>
#include <vector>
#include <json_conversions.h>

View File

@ -38,7 +38,7 @@
#include <dialogs/dialog_update_notice.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <core/json_serializers.h>
#include <wx/log.h>

View File

@ -24,7 +24,7 @@
#ifndef JSON_SERIALIZERS_H_
#define JSON_SERIALIZERS_H_
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <wx/string.h>
#include <optional>

View File

@ -26,7 +26,7 @@
#include <drc/drc_item.h>
#include <fstream>
#include <macros.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <rc_json_schema.h>

View File

@ -30,7 +30,7 @@
#ifndef GERBER_JOBFILE_WRITER_H
#define GERBER_JOBFILE_WRITER_H
#include <nlohmann/json.hpp>
#include <json_common.h>
// A helper enum to handle sides of some layers (silk, mask)

View File

@ -24,7 +24,7 @@
#include <netlist_lexer.h> // netlist_lexer is common to Eeschema and Pcbnew
#include <string_utils.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include "pcb_netlist.h"
#include "netlist_reader.h"

View File

@ -28,7 +28,7 @@
#include <boost/ptr_container/ptr_vector.hpp>
#include <wx/arrstr.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <unordered_set>
#include <lib_id.h>

View File

@ -46,7 +46,7 @@
#include <tool/tool_manager.h>
#include <tools/pcb_selection_tool.h>
#include <dialogs/dialog_design_block_properties.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
bool checkOverwriteDb( wxWindow* aFrame, wxString& libname, wxString& newName )
{

View File

@ -26,7 +26,7 @@
#include <memory>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <core/map_helpers.h>
#include <core/json_serializers.h>
#include <string_utils.h>

View File

@ -37,7 +37,7 @@
#include <wx/string.h>
#include <wx/arrstr.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <board_item_container.h>
class BOARD;

View File

@ -41,7 +41,7 @@
#include <wx/zipstrm.h>
#include <wx/stdstream.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <core/map_helpers.h>

View File

@ -27,7 +27,7 @@
#include <memory>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <core/json_serializers.h>
#include <core/map_helpers.h>
#include <string_utils.h>

View File

@ -37,7 +37,7 @@
#include <wx/string.h>
#include <wx/arrstr.h>
#include <nlohmann/json.hpp>
#include <json_common.h>
#include <board_item_container.h>
#include <pcb_shape.h>

View File

@ -153,6 +153,137 @@ using nanodbc::wide_string;
#endif
#endif
/***********************************************************************************************************************
*
* KICAD-SPECIFIC ADDITION
*
* If we are compiling on Apple with Clang >= 17, the version of LLVM no longer includes a generic template for
* char_traits for char types which are not specified in the C++ standard. We define our own here for types required by
* the database library.
*
* From: https://github.com/llvm/llvm-project/commit/c3668779c13596e223c26fbd49670d18cd638c40
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
**********************************************************************************************************************/
#ifdef __APPLE__
#if __clang_major__ >= 17
template <>
struct std::char_traits<NANODBC_SQLCHAR>
{
using char_type = NANODBC_SQLCHAR;
using int_type = int;
using off_type = std::streamoff;
using pos_type = std::streampos;
using state_type = mbstate_t;
static inline void assign( char_type& __c1, const char_type& __c2 ) noexcept { __c1 = __c2; }
static inline bool eq( char_type __c1, char_type __c2 ) noexcept { return __c1 == __c2; }
static inline bool lt( char_type __c1, char_type __c2 ) noexcept { return __c1 < __c2; }
static constexpr int compare( const char_type* __s1, const char_type* __s2, size_t __n )
{
for( ; __n; --__n, ++__s1, ++__s2 )
{
if( lt( *__s1, *__s2 ) )
return -1;
if( lt( *__s2, *__s1 ) )
return 1;
}
return 0;
}
static size_t length( const char_type* __s )
{
size_t __len = 0;
for( ; !eq( *__s, char_type( 0 ) ); ++__s )
++__len;
return __len;
}
static constexpr const char_type* find( const char_type* __s, size_t __n, const char_type& __a )
{
for( ; __n; --__n )
{
if( eq( *__s, __a ) )
return __s;
++__s;
}
return nullptr;
}
static constexpr char_type* move( char_type* __s1, const char_type* __s2, size_t __n )
{
if( __n == 0 )
return __s1;
char_type* __r = __s1;
if( __s1 < __s2 )
{
for( ; __n; --__n, ++__s1, ++__s2 )
assign( *__s1, *__s2 );
}
else if( __s2 < __s1 )
{
__s1 += __n;
__s2 += __n;
for( ; __n; --__n )
assign( *--__s1, *--__s2 );
}
return __r;
}
static constexpr char_type* copy( char_type* __s1, const char_type* __s2, size_t __n )
{
char_type* __r = __s1;
for( ; __n; --__n, ++__s1, ++__s2 )
assign( *__s1, *__s2 );
return __r;
}
static char_type* assign( char_type* __s, size_t __n, char_type __a )
{
char_type* __r = __s;
for( ; __n; --__n, ++__s )
assign( *__s, __a );
return __r;
}
static inline constexpr int_type not_eof( int_type __c ) noexcept
{
return eq_int_type( __c, eof() ) ? ~eof() : __c;
}
static inline char_type to_char_type( int_type __c ) noexcept { return char_type( __c ); }
static inline int_type to_int_type( char_type __c ) noexcept { return static_cast<int_type>( __c ); }
static inline constexpr bool eq_int_type( int_type __c1, int_type __c2 ) noexcept { return __c1 == __c2; }
static inline constexpr int_type eof() noexcept { return static_cast<int_type>( EOF ); }
};
#endif
#endif
// clang-format off
// .d88888b. 8888888b. 888888b. .d8888b. 888b d888
// d88P" "Y88b 888 "Y88b 888 "88b d88P Y88b 8888b d8888