Skip to content

Commit 1fb67d6

Browse files
authored
fix: Fix a bug in isAutoCreationClass<T>. (#2277)
1 parent cbf63f8 commit 1fb67d6

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

lib/inc/drogon/DrObject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ template <typename T>
6161
struct isAutoCreationClass
6262
{
6363
template <class C>
64-
static constexpr auto check(C *)
65-
-> std::enable_if_t<std::is_same_v<decltype(C::isAutoCreation), bool>,
66-
bool>
64+
static constexpr auto check(C *) -> std::enable_if_t<
65+
std::is_same_v<decltype(C::isAutoCreation), const bool>,
66+
bool>
6767
{
6868
return C::isAutoCreation;
6969
}

lib/tests/unittests/DrObjectTest.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <drogon/DrObject.h>
22
#include <drogon/drogon_test.h>
3+
#include <drogon/HttpController.h>
34

45
using namespace drogon;
56

@@ -41,3 +42,45 @@ DROGON_TEST(DrObjectNamespaceTest)
4142
CHECK(objPtr2.get() != nullptr);
4243
CHECK(objPtr == objPtr2);
4344
}
45+
46+
class TestC : public DrObject<TestC>
47+
{
48+
public:
49+
static constexpr bool isAutoCreation = true;
50+
};
51+
52+
class TestD : public DrObject<TestD>
53+
{
54+
public:
55+
static constexpr bool isAutoCreation = false;
56+
};
57+
58+
class TestE : public DrObject<TestE>
59+
{
60+
public:
61+
static constexpr double isAutoCreation = 3.0;
62+
};
63+
64+
class CtrlA : public HttpController<CtrlA>
65+
{
66+
public:
67+
METHOD_LIST_BEGIN
68+
METHOD_LIST_END
69+
};
70+
71+
class CtrlB : public HttpController<CtrlB, false>
72+
{
73+
public:
74+
METHOD_LIST_BEGIN
75+
METHOD_LIST_END
76+
};
77+
78+
DROGON_TEST(IsAutoCreationClassTest)
79+
{
80+
STATIC_REQUIRE(isAutoCreationClass<TestA>::value == false);
81+
STATIC_REQUIRE(isAutoCreationClass<TestC>::value == true);
82+
STATIC_REQUIRE(isAutoCreationClass<TestD>::value == false);
83+
STATIC_REQUIRE(isAutoCreationClass<TestE>::value == false);
84+
STATIC_REQUIRE(isAutoCreationClass<CtrlA>::value == true);
85+
STATIC_REQUIRE(isAutoCreationClass<CtrlB>::value == false);
86+
}

0 commit comments

Comments
 (0)