]> git.tdb.fi Git - builder.git/commitdiff
Use dynamic_cast to reference when incorrect type is not acceptable
authorMikko Rasa <tdb@tdb.fi>
Tue, 20 Dec 2022 12:03:45 +0000 (14:03 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 20 Dec 2022 12:05:13 +0000 (14:05 +0200)
source/gnuarchiver.cpp
source/gnulinker.cpp
source/msvcarchiver.cpp
source/msvclinker.cpp

index 742278de668653f17895abab2e6d003fc9698e16..f802031f0ee8ea83d12eba4da1019dcb9d2e7142 100644 (file)
@@ -28,12 +28,7 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
 
        list<ObjectFile *> objs;
        for(Target *s: sources)
-       {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
-                       objs.push_back(obj);
-               else
-                       throw invalid_argument("GnuArchiver::create_target");
-       }
+               objs.push_back(&dynamic_cast<ObjectFile &>(*s));
 
        const Component &comp = *objs.front()->get_component();
        StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
index 0d730a4a30f3a26dd3dc1e50b92f15db54481ef8..ddad8d1904abb06fb7252128b7bd586593599a81 100644 (file)
@@ -47,14 +47,10 @@ Target *GnuLinker::create_target(const list<Target *> &sources, const string &ar
        Linker *linker = default_linker;
        for(Target *s: sources)
        {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(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<ObjectFile &>(*s);
+               objs.push_back(&obj);
+               if(obj.get_tool()->get_tag()=="CXX")
+                       linker = cxx_linker;
        }
 
        const Component &comp = *objs.front()->get_component();
index 5ac406b008b6029c87b61ba7c999c77dc60ab1e3..4a44bee593f463a94ef4702ee75b2410a611d037 100644 (file)
@@ -26,12 +26,7 @@ Target *MsvcArchiver::create_target(const list<Target *> &sources, const string
 
        list<ObjectFile *> objs;
        for(Target *s: sources)
-       {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
-                       objs.push_back(obj);
-               else
-                       throw invalid_argument("MsvcArchiver::create_target");
-       }
+               objs.push_back(&dynamic_cast<ObjectFile &>(*s));
 
        const Component &comp = *objs.front()->get_component();
        StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
index 8ff4d9cdd96dc98df028f60d80c579a2b7c40550..4495db7260f533b3a6842e7641e4da5af5a70b37 100644 (file)
@@ -36,12 +36,7 @@ Target *MsvcLinker::create_target(const list<Target *> &sources, const string &a
 
        list<ObjectFile *> objs;
        for(Target *s: sources)
-       {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
-                       objs.push_back(obj);
-               else
-                       throw invalid_argument("MsvcLinker::create_target");
-       }
+               objs.push_back(&dynamic_cast<ObjectFile &>(*s));
 
        const Component &comp = *objs.front()->get_component();
        Binary *bin = 0;