Closed AlexZhu2001 closed 1 month ago
By the way, it seems that only this version of MSVC will have this error, while version 19.38.33133 of MSVC does not seem to have any errors.
This is very interesting, thanks for the issue. What is clearly happening is that get_field_name_str_view
is not doing what it is supposed to be doing:
https://github.com/getml/reflect-cpp/blob/main/include/rfl/internal/get_field_names.hpp
I will try to reproduce the problem.
Hi @AlexZhu2001 , so the reason it doesn't compile with 19.29.30153 is that the version for the compiler is simply too old. It doesn't have anything to do with the templating.
As we clearly state in our README, reflect-cpp requires at least MSVC 17.8, which corresponds to version 19.38. (MSVC versioning numbering is very confusing...) As you have correctly observed, it works for 19.38.
Take this simple example program:
#include <source_location>
#include <string_view>
#include <iostream>
#include <string>
template <class T, auto ptr>
consteval auto get_field_name_str_view() {
const auto func_name = std::string_view{std::source_location::current().function_name()};
const auto split = func_name.substr(0, func_name.size() - 7);
return split.substr(split.rfind("->") + 2);
}
struct Test{int a;};
static constexpr auto test = Test{};
consteval auto get_f1() {
auto& [f1] = test;
return &f1;
}
int main(int argc, const char** argv) {
constexpr auto ptr = get_f1();
constexpr auto str = get_field_name_str_view<Test, ptr>();
static_assert(get_field_name_str_view<Test, &test.a>() == "a", "Failed");
std::cout << str << std::endl;
return 0;
}
You can insert it in godbolt.org...it compiles with 19.38, no problem. But it will fail with 19.29.
@AlexZhu2001, I have added your example as a test:
https://github.com/getml/reflect-cpp/blob/f/templates/tests/json/test_template.cpp
As you can see, the Github Action pipelines run through for all compilers, including MSVC:
https://github.com/getml/reflect-cpp/commits/f/templates/
So I would argue that this is simply an issue with an unsupported compiler.
But thank you for opening this issue. At the very least, we got another test out of it.
Okay, the version number of MSVC is really confusing. I will upgrade to the corresponding supported version.
Hi, I received some compilation errors when using MSVC with the following test code.
This code works fine when using clang and mingw. The msvc version is
19.29.30153 for x64
The compiled output is as follows