CppSharp icon indicating copy to clipboard operation
CppSharp copied to clipboard

Error when inheriting from std::exception

Open phil-zxx opened this issue 5 years ago • 3 comments

I have a Error.hpp file that contains

class Error : public std::exception
{
public:
    Error(const std::string& fileName, const std::string& funcName, const std::string& errMsg);

    const char* what() const noexcept override;

private:
    const std::string m_message;
};

inheriting from class std::exception. The CLI output code in the generated Error.h file is

public ref class Error : ::Std::Exception
{
public:
    Error(::Error* native);
    Error(::Error* native, bool ownNativeInstance);
    static Error^ __CreateInstance(::System::IntPtr native);
    static Error^ __CreateInstance(::System::IntPtr native, bool __ownsNativeInstance);
    Error(System::String^ fileName, System::String^ funcName, System::String^ errMsg);

    ~Error();

    property System::String^ What
    {
        System::String^ get();
    }
};

Unfortunately, VS underlines ::Std::Exception saying

Severity   Code    Description
Error      C2039   'Std': is not a member of '`global namespace''
Error      C3083   'Std': the symbol to the left of a '::' must be a type
Error      C2039   Exception': is not a member of '`global namespace''
Error      C2504   Exception': base class undefined

Are there any settings I need to consider so that code for ::Std::Exception is generated? Note, the generated file Std.cpp is empty, and Std.h only contains

#pragma once
#include "CppSharp.h"
#include <C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/include/yvals_core.h>

Any help appreciated.

phil-zxx avatar Nov 25 '20 17:11 phil-zxx

@phil-zxx unfortunately we still don't support all of STD since it's very large and we go on a case by case basis for now. We're considering an optional list of classes users can modify where they can specify which STD classes they need so that we can wrap them.

ddobrev avatar Nov 30 '20 22:11 ddobrev

@ddobrev I think the problem is that we generate broken code by default.

It's fine to not support it, but it should be ignored, not fail like this.

tritao avatar Nov 30 '20 23:11 tritao

@tritao correct, we have 2 problems here.

ddobrev avatar Nov 30 '20 23:11 ddobrev