error: explicit instantiation of 'assign' does not refer to a function template, variable template, member function, member class, or static data member

Open
#1,386 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, csharp
Domain
tooling

Research direction

Start with the supplied CSharpAPI.h and Setup method, then reproduce generation for the CSharp binding with Clang. Inspect the generated Std-symbols.cpp, especially the explicit std::basic_string::assign declaration, and compare it with the available libc++ overloads. Done means the generated C++ compiles without the reported explicit-instantiation error.

Written by the indexing model from the issue text.

Description

Brief Description

I want to generate a simple binding that converts C# System.string arguments to C++ std::string. After generating the code there's an error in the file Std-symbols.cpp.

OS: macOS Catalina

IDE: Qt Creator

Used headers
#include <string>

class CSharpAPI
{
public:
    CSharpAPI();

    void SetVariable(std::string strName, std::string strValue);
};
Used settings
public void Setup(Driver driver)
{
    var options = driver.Options;
    options.GeneratorKind = GeneratorKind.CSharp;
    options.GenerateInternalImports = true;
    var module = options.AddModule("MyModule");
    module.IncludeDirs.Add("../Include");
    module.Headers.Add("CSharpAPI.h");
}

Target: Clang

Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix

Other settings

Stack trace or incompilable generated code

Std-symbols.cpp:

#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
#define _LIBCPP_HIDE_FROM_ABI

#include <string>
#include <new>

template std::allocator<char>::allocator() noexcept;
template std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string();
template std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept;
template void* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const char*);
template const char* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::data() const noexcept;

Error:

Std-symbols.cpp:10: error: explicit instantiation of 'assign' does not refer to a function template, variable template, member function, member class, or static data member
template void* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(const char*);
                                                                                      ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/string:1055:18: note: candidate template ignored: could not match 'const type-parameter-0-0 &' against 'const char *'
                 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
                 ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/string:1072:19: note: candidate template ignored: could not match 'const type-parameter-0-0 &' against 'const char *'
                  assign(const _Tp & __t, size_type __pos, size_type __n=npos);
                  ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/string:1084:9: note: candidate template ignored: failed template argument deduction
        assign(_InputIterator __first, _InputIterator __last);
        ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/string:1093:9: note: candidate template ignored: failed template argument deduction
        assign(_ForwardIterator __first, _ForwardIterator __last);
        ^
Dominant language
C#
Stars
3.4k
Forks
541
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mono/CppSharp

All issues in mono/CppSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.