Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test from bugreport, provide compile time diagnostics for such cases #85

Merged
merged 6 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/boost/dll/detail/demangling/msvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void mangled_storage_impl::trim_typename(std::string & val)
static constexpr char class_ [7] = "class ";
static constexpr char struct_[8] = "struct ";

if (equal(begin(class_), end(class_)-1, val.begin())) //aklright, starts with 'class '
if (equal(begin(class_), end(class_)-1, val.begin()))
val.erase(0, 6);
else if (val.size() >= 7)
if (equal(begin(struct_), end(struct_)-1, val.begin()))
Expand All @@ -98,7 +98,7 @@ namespace parser {
parser::try_consume_prefix(s, prefix);
return true;
}

inline void consume_ptrs(boost::core::string_view& s) {
do {
while (parser::try_consume_prefix(s, " ")) {}
Expand Down Expand Up @@ -126,6 +126,15 @@ namespace parser {
parser::ignore_prefix(s, "struct ");

const auto& mangled_name = ms.get_name<T>();

static_assert(
!std::is_function<typename std::remove_pointer<T>::type>::value,
"boost::dll::smart_library on Windows platform does not support "
"functions that accept functions. If you wish to see such support "
"- please provide a working PR on github with sufficient tests. "
"Otherwise simplify the function. For example, use `void*` "
"parameter instead of a function pointer. "
);
if (!parser::try_consume_prefix(s, mangled_name)) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ project
[ run shared_library_concurrent_load_test.cpp /boost/thread//boost_thread : : library1 library2 my_plugin_aggregator refcounting_plugin : <link>shared ]
[ run cpp_mangle_test.cpp : : cpp_plugin ]
[ run cpp_mangling.cpp ]
[ compile-fail cpp_mangling1_cf.cpp ]
[ run cpp_load_test.cpp : : cpp_plugin ]
[ run cpp_import_test.cpp : : cpp_plugin ]
[ run template_method_linux_test.cpp : : cpp_plugin ]
Expand Down
30 changes: 30 additions & 0 deletions test/cpp_mangling1_cf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#include <boost/dll/detail/demangling/msvc.hpp>

struct CallbackInfo;

#ifdef _MSC_VER
typedef void(__stdcall* Callback)(CallbackInfo* pInfo);
#else
typedef void(*Callback)(CallbackInfo* pInfo);
#endif


int main() {
namespace parser = boost::dll::detail::parser;
boost::dll::detail::mangled_storage_impl ms;

// The following case of mangling is not supported at the moment. Make
// sure that we detect it on compile time.
parser::is_mem_fn_with_name<int, void(*)(Callback)>("set_callback", ms)
("public: void __cdecl int::set_callback(void (__cdecl*)(struct CallbackInfo * __ptr64)) __ptr64")
;
}

Loading