From: Mikko Rasa Date: Tue, 20 Dec 2022 12:03:45 +0000 (+0200) Subject: Use dynamic_cast to reference when incorrect type is not acceptable X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=45dd0aa6e8f2107f1bd7d37fe4b171ee2259af60;p=builder.git Use dynamic_cast to reference when incorrect type is not acceptable --- diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 742278d..f802031 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -28,12 +28,7 @@ Target *GnuArchiver::create_target(const list &sources, const string & list objs; for(Target *s: sources) - { - if(ObjectFile *obj = dynamic_cast(s)) - objs.push_back(obj); - else - throw invalid_argument("GnuArchiver::create_target"); - } + objs.push_back(&dynamic_cast(*s)); const Component &comp = *objs.front()->get_component(); StaticLibrary *lib = new StaticLibrary(builder, comp, objs); diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 0d730a4..ddad8d1 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -47,14 +47,10 @@ Target *GnuLinker::create_target(const list &sources, const string &ar Linker *linker = default_linker; for(Target *s: sources) { - if(ObjectFile *obj = dynamic_cast(s)) - { - objs.push_back(obj); - if(obj->get_tool()->get_tag()=="CXX") - linker = cxx_linker; - } - else - throw invalid_argument("GnuLinker::create_target"); + ObjectFile &obj = dynamic_cast(*s); + objs.push_back(&obj); + if(obj.get_tool()->get_tag()=="CXX") + linker = cxx_linker; } const Component &comp = *objs.front()->get_component(); diff --git a/source/msvcarchiver.cpp b/source/msvcarchiver.cpp index 5ac406b..4a44bee 100644 --- a/source/msvcarchiver.cpp +++ b/source/msvcarchiver.cpp @@ -26,12 +26,7 @@ Target *MsvcArchiver::create_target(const list &sources, const string list objs; for(Target *s: sources) - { - if(ObjectFile *obj = dynamic_cast(s)) - objs.push_back(obj); - else - throw invalid_argument("MsvcArchiver::create_target"); - } + objs.push_back(&dynamic_cast(*s)); const Component &comp = *objs.front()->get_component(); StaticLibrary *lib = new StaticLibrary(builder, comp, objs); diff --git a/source/msvclinker.cpp b/source/msvclinker.cpp index 8ff4d9c..4495db7 100644 --- a/source/msvclinker.cpp +++ b/source/msvclinker.cpp @@ -36,12 +36,7 @@ Target *MsvcLinker::create_target(const list &sources, const string &a list objs; for(Target *s: sources) - { - if(ObjectFile *obj = dynamic_cast(s)) - objs.push_back(obj); - else - throw invalid_argument("MsvcLinker::create_target"); - } + objs.push_back(&dynamic_cast(*s)); const Component &comp = *objs.front()->get_component(); Binary *bin = 0;