Skip to content

Commit a90a4e3

Browse files
authored
Merge pull request #1255 from Geode-solutions/fix/dyn-cast-singleton
fix(Basic): use static_cast of Singleton instance
2 parents 0db236e + 638f54c commit a90a4e3

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Checks: >
1919
-readability-use-anyofallof,
2020
-readability-redundant-access-specifiers,
2121
-readability-convert-member-functions-to-static,
22-
-cppcoreguidelines-avoid-const-or-ref-data-members
22+
-cppcoreguidelines-avoid-const-or-ref-data-members,
23+
-cppcoreguidelines-pro-bounds-constant-array-index
2324
2425
CheckOptions:
2526
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic

include/geode/basic/singleton.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ namespace geode
6161
{
6262
const auto& type = typeid( SingletonType );
6363
const std::lock_guard< std::mutex > locking{ lock() };
64-
auto* singleton =
65-
dynamic_cast< SingletonType* >( instance( type ) );
64+
auto* singleton = instance( type );
6665
if( singleton == nullptr )
6766
{
6867
singleton = new SingletonType{};
6968
set_instance( type, singleton );
7069
}
71-
return *singleton;
70+
return *static_cast< SingletonType* >( singleton );
7271
}
7372

7473
private:

0 commit comments

Comments
 (0)