Skip to content

Commit 96e8f19

Browse files
Pierre-Luc GagnéCopilot
andcommitted
fix: MSVC compiler compatibility in consteval name-extraction functions
column_field.hpp (tag_to_column_name): - Add MSVC-specific end delimiters: MSVC __FUNCSIG__ closes the template argument with '>' (e.g. tag_to_column_name<struct 'anonymous'::tag>) rather than ';'/'_tag]' used in GCC/Clang __PRETTY_FUNCTION__. Without this, both end1 and end2 are npos and the static_assert fires. schema_generator.hpp (extract_type_name): - Rewrite to use constexpr local variables and ternary expressions in place of if/else chains. In a consteval function MSVC instantiates per-type, making each find() result a known compile-time constant; comparing those against npos in a regular 'if' triggers warning C4127 ('conditional expression is constant') which /WX promotes to an error. Switching to constexpr + ternary eliminates all C4127 warnings. - Also convert marker_pos/start/end to constexpr so if constexpr can guard the npos fallback path cleanly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3040cd4 commit 96e8f19

2 files changed

Lines changed: 26 additions & 28 deletions

File tree

lib/include/ds_mysql/column_field.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ consteval std::string_view tag_to_column_name() noexcept {
6161
return {};
6262
}
6363
constexpr auto start = key_pos + key.size();
64+
#if defined(_MSC_VER)
65+
// MSVC __FUNCSIG__: "...tag_to_column_name<struct `anonymous-namespace'::tag>(void)..."
66+
// The tag type ends at '>' (template arg close); '(' is a secondary fallback.
67+
constexpr auto end1 = sig.find('>', start);
68+
constexpr auto end2 = sig.find('(', start);
69+
#else
6470
constexpr auto end1 = sig.find(';', start);
6571
constexpr auto end2 = sig.find(']', start);
72+
#endif
6673
constexpr auto end = (end1 != npos && end2 != npos) ? ((end1 < end2) ? end1 : end2) :
6774
(end1 != npos) ? end1 :
6875
(end2 != npos) ? end2 : npos;

lib/include/ds_mysql/schema_generator.hpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -185,43 +185,34 @@ consteval std::string_view extract_type_name() {
185185
return "unknown";
186186
#endif
187187

188-
auto const marker_pos = signature.find(marker);
189-
if (marker_pos == std::string_view::npos) {
188+
constexpr auto npos = std::string_view::npos;
189+
constexpr auto marker_pos = signature.find(marker);
190+
if constexpr (marker_pos == npos) {
190191
return "unknown";
191192
}
192193

193-
auto const start = marker_pos + marker.size();
194+
constexpr auto start = marker_pos + marker.size();
194195

195196
#if defined(__clang__) || defined(__GNUC__)
196197
// GCC/Clang format: [with T = TYPE] or [with T = TYPE; ALIAS = EXPANSION, ...]
197-
// Neither ';' nor ']' can appear in a C++ type name, making them safe end delimiters.
198-
auto const end_semicolon = signature.find(';', start);
199-
auto const end_bracket = signature.find(']', start);
200-
201-
auto end = std::string_view::npos;
202-
if (end_semicolon != std::string_view::npos && end_bracket != std::string_view::npos) {
203-
end = end_semicolon < end_bracket ? end_semicolon : end_bracket;
204-
} else if (end_semicolon != std::string_view::npos) {
205-
end = end_semicolon;
206-
} else if (end_bracket != std::string_view::npos) {
207-
end = end_bracket;
208-
}
198+
constexpr auto end_semicolon = signature.find(';', start);
199+
constexpr auto end_bracket = signature.find(']', start);
200+
constexpr auto end = (end_semicolon != npos && end_bracket != npos)
201+
? (end_semicolon < end_bracket ? end_semicolon : end_bracket)
202+
: (end_semicolon != npos ? end_semicolon
203+
: end_bracket != npos ? end_bracket : npos);
209204
#else
210-
// MSVC format: extract_type_name<TYPE>
211-
auto const end_bracket = signature.find('>', start);
212-
auto const end_comma = signature.find(',', start);
213-
214-
auto end = std::string_view::npos;
215-
if (end_bracket != std::string_view::npos && end_comma != std::string_view::npos) {
216-
end = end_bracket < end_comma ? end_bracket : end_comma;
217-
} else if (end_bracket != std::string_view::npos) {
218-
end = end_bracket;
219-
} else if (end_comma != std::string_view::npos) {
220-
end = end_comma;
221-
}
205+
// MSVC format: "...extract_type_name<TYPE>(void)..."
206+
// The type ends at '>' (template arg close) or ',' (comma in multi-param templates).
207+
constexpr auto end_bracket = signature.find('>', start);
208+
constexpr auto end_comma = signature.find(',', start);
209+
constexpr auto end = (end_bracket != npos && end_comma != npos)
210+
? (end_bracket < end_comma ? end_bracket : end_comma)
211+
: (end_bracket != npos ? end_bracket
212+
: end_comma != npos ? end_comma : npos);
222213
#endif
223214

224-
if (end == std::string_view::npos || end <= start) {
215+
if constexpr (end == npos || end <= start) {
225216
return "unknown";
226217
}
227218

0 commit comments

Comments
 (0)