Skip to content

Commit 4a1a6b4

Browse files
Pierre-Luc GagnéCopilot
andcommitted
fix: strip MSVC elaborated type specifiers from extracted type names
MSVC's __FUNCSIG__ prepends 'struct ' or 'class ' to type names when there is no explicit scope qualifier (e.g. anonymous-namespace types may appear as 'struct child_table_cascade' rather than '`anonymous-namespace'::child_table_cascade'). When rfind("::") returns npos (no scope to strip), the full string including 'struct '/'class ' was used as the table/column name, producing e.g. CREATE TABLE struct child_table_cascade. Fix: strip the elaborated type keyword prefix immediately after substring extraction, before the scope-stripping and _tag-suffix steps. Applied to both tag_to_column_name (column_field.hpp) and extract_type_name (schema_generator.hpp). GCC/Clang are unaffected since their __PRETTY_FUNCTION__ output never includes these keywords. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 30d60d6 commit 4a1a6b4

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/include/ds_mysql/column_field.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ consteval std::string_view tag_to_column_name() noexcept {
7878
return {};
7979
}
8080
auto name = sig.substr(start, end - start);
81+
// MSVC prepends 'struct ' or 'class ' to type names; strip before scope/suffix processing.
82+
if (name.starts_with("struct ")) {
83+
name = name.substr(7);
84+
} else if (name.starts_with("class ")) {
85+
name = name.substr(6);
86+
}
8187
auto const scope = name.rfind("::");
8288
if (scope != std::string_view::npos && scope + 2 < name.size()) {
8389
name = name.substr(scope + 2);

lib/include/ds_mysql/schema_generator.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ consteval std::string_view extract_type_name() {
218218

219219
auto name = signature.substr(start, end - start);
220220

221+
// MSVC prepends 'struct ' or 'class ' to type names; strip before scope processing.
222+
if (name.starts_with("struct ")) {
223+
name = name.substr(7);
224+
} else if (name.starts_with("class ")) {
225+
name = name.substr(6);
226+
}
227+
221228
// Remove namespace qualifiers (keep only the final name)
222229
auto const scope_pos = name.rfind("::");
223230
if (scope_pos != std::string_view::npos && scope_pos + 2 < name.size()) {

0 commit comments

Comments
 (0)