mirror of
https://github.com/serge1/COFFI
synced 2026-06-08 17:24:32 +00:00
Fix all remaining MSVC warnings (C4244, C4267, C4250)
C4244/C4267: Instead of manually expanding macros at each call site, fix the COFFI_SET_ACCESS and COFFI_GET_SET_ACCESS macros to use narrow_cast<decltype(header.NAME)>(value) in the setter. This handles all narrowing conversions (uint64_t->uint32_t in win_header_pe, uint32_t->uint16_t in section_header, size_t->uint32_t) globally. Revert the previous manual expansions for reloc_count/line_num_count back to macro usage since the macro now handles it. C4250: Suppress the diamond virtual inheritance dominance warning with a comment explaining the design: coffi_strings and coffi_symbols both virtually inherit string_to_name_provider, and the dominant path through coffi_strings is the intended resolution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
Serge Lamikhov-Center
parent
be43dfab51
commit
1d7b4ba3a1
@@ -33,6 +33,12 @@ THE SOFTWARE.
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
// C4250: 'coffi' inherits 'coffi_strings::method' via dominance.
|
||||
// This is expected and correct — coffi uses diamond virtual inheritance
|
||||
// (coffi_strings and coffi_symbols both virtually inherit
|
||||
// string_to_name_provider). The dominant path through coffi_strings
|
||||
// is the intended resolution; the behavior is well-defined in C++.
|
||||
#pragma warning(disable : 4250)
|
||||
//#pragma warning(disable:4355)
|
||||
//#pragma warning(disable:4244)
|
||||
#endif
|
||||
|
||||
+2
-12
@@ -131,18 +131,8 @@ template <class T> class section_impl_tmpl : public section
|
||||
COFFI_GET_SET_ACCESS(uint32_t, virtual_address);
|
||||
COFFI_GET_SET_ACCESS(uint32_t, data_offset);
|
||||
COFFI_GET_SET_ACCESS(uint32_t, reloc_offset);
|
||||
uint32_t get_reloc_count() const { return header.reloc_count; }
|
||||
void set_reloc_count(uint32_t value)
|
||||
{
|
||||
header.reloc_count =
|
||||
narrow_cast<decltype(header.reloc_count)>(value);
|
||||
}
|
||||
uint32_t get_line_num_count() const { return header.line_num_count; }
|
||||
void set_line_num_count(uint32_t value)
|
||||
{
|
||||
header.line_num_count =
|
||||
narrow_cast<decltype(header.line_num_count)>(value);
|
||||
}
|
||||
COFFI_GET_SET_ACCESS(uint32_t, reloc_count);
|
||||
COFFI_GET_SET_ACCESS(uint32_t, line_num_count);
|
||||
COFFI_GET_SET_ACCESS(uint32_t, flags);
|
||||
|
||||
COFFI_GET_SIZEOF();
|
||||
|
||||
@@ -65,12 +65,12 @@ THE SOFTWARE.
|
||||
|
||||
//! Defines a **set_NAME** function for accessing the **NAME** structure field.
|
||||
#define COFFI_SET_ACCESS(TYPE, NAME) \
|
||||
void set_##NAME(TYPE value) { header.NAME = value; }
|
||||
void set_##NAME(TYPE value) { header.NAME = narrow_cast<decltype(header.NAME)>(value); }
|
||||
|
||||
//! Defines a **get_NAME** and a **set_NAME** functions for accessing the **NAME** structure field.
|
||||
#define COFFI_GET_SET_ACCESS(TYPE, NAME) \
|
||||
TYPE get_##NAME() const { return header.NAME; } \
|
||||
void set_##NAME(TYPE value) { header.NAME = value; }
|
||||
void set_##NAME(TYPE value) { header.NAME = narrow_cast<decltype(header.NAME)>(value); }
|
||||
|
||||
//! Disables the **get_NAME** function for prohibiting read accesses to the **NAME** structure field.
|
||||
#define COFFI_GET_ACCESS_NONE(TYPE, NAME) \
|
||||
|
||||
Reference in New Issue
Block a user