Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce scope for variables used for dynamic_cast to subclass.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 May 2022 08:17:57 +0000 (10:17 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 May 2022 08:17:57 +0000 (10:17 +0200)
Use the init-statement to declare variables inside the if statement (sonar).

examples/cpp/dag-from-dax/s4u-dag-from-dax.cpp
examples/cpp/dag-from-dot/s4u-dag-from-dot.cpp

index a1b8538..a6c2538 100644 (file)
@@ -46,8 +46,7 @@ int main(int argc, char** argv)
   static_cast<sg4::Exec*>(dag.back().get())->set_host(hosts[0]);
 
   for (const auto& a : dag) {
-    auto* exec = dynamic_cast<sg4::Exec*>(a.get());
-    if (exec != nullptr && exec->get_name() != "end") {
+    if (auto* exec = dynamic_cast<sg4::Exec*>(a.get()); exec != nullptr && exec->get_name() != "end") {
       exec->set_host(hosts[cursor % count]);
       cursor++;
     }
index ca994ac..ef2d22f 100644 (file)
@@ -44,8 +44,7 @@ int main(int argc, char** argv)
   static_cast<sg4::Exec*>(dag.back().get())->set_host(hosts[0]);
 
   for (const auto& a : dag) {
-    auto* exec = dynamic_cast<sg4::Exec*>(a.get());
-    if (exec != nullptr && exec->get_name() != "end") {
+    if (auto* exec = dynamic_cast<sg4::Exec*>(a.get()); exec != nullptr && exec->get_name() != "end") {
       exec->set_host(hosts[cursor % count]);
       cursor++;
     }