GithubHelp home page GithubHelp logo

Comments (4)

timotheecour avatar timotheecour commented on July 30, 2024

workaround: skip generating opCast!T from C++ operator T()
obviously this is not a good workaround since it'll skip generating some C++ functions

Calypso/ddmd/cpp/calypso.cpp:

Identifier *getIdentifierOrNull(const clang::NamedDecl *D, SpecValue *spec, bool useCanonicalType)

    else if (auto Conv = dyn_cast<clang::CXXConversionDecl>(D))
    {
       // return immediately here, which skips generating opCast!T from C++ `operator T()`
        return nullptr;
       // ...
}

NOTE: I had intially tried in Calypso/ddmd/expression.d CastExp:semantic(Scope* sc) commenting out the block if (Expression e = op_overload(sc)){ but it had worse side effects as it'll just skip existing opCast templates

A better workaround would be to generate opCast(BaseClass*) if at least one clang::CXXConversionDecl is encountered (and generated) but I don't know how this could be done simply in current design. Any help appreciated.

from calypso.

timotheecour avatar timotheecour commented on July 30, 2024

still a better workaround (requiring no change in Calypso/ddmd/cpp/calypso.cpp, hence not suppressing generation of opCast's):

Calypso/ddmd/expression.d in class CastExp:

if (!to.equals(e1.type) && mod == cast(ubyte)~0)
        {
            uint errors = global.startGagging();
            Expression e = op_overload(sc);
            if(global.endGagging(errors))
                e=null;
            if(e)
              return e.implicitCastTo(sc, to);
        }
  • what could be downsides?
  • how could we require this change to only apply for C++ classes?

from calypso.

timotheecour avatar timotheecour commented on July 30, 2024

improved version that only gags when both e1.type and to are C++ classes from langPlugin:

                    bool is_cpp_class(Type t){
                        // NOTE: this doesn't work:
                        // if(auto cd = t.isClassHandle()) return cd.isCPPclass();

                        Type tv = t.baseElemOf();
                        if (!tv.isAggregateValue()) return false;
                        if(!tv.getAggregateSym().langPlugin()) return false;
                        return true;
                    }
                    if(!is_cpp_class(e1.type)) goto Handle_default;
                    if(!is_cpp_class(to)) goto Handle_default;

                    uint errors = global.startGagging();
                    Expression e = op_overload(sc);
                    if(global.endGagging(errors)){
                        e=null;
                    }
                    if(e){
                        return e.implicitCastTo(sc, to);
                    }
                    goto Handle_other; // TODO: needed?
                }

                Handle_default:
                    if (Expression e = op_overload(sc)){
                        return e.implicitCastTo(sc, to);
                    }
                Handle_other:

from calypso.

Syniurge avatar Syniurge commented on July 30, 2024

Fixed by c3573b9.

from calypso.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.