Skip to content

Commit 1d52872

Browse files
committed
removed const char* constants.
1 parent 8a0d782 commit 1d52872

25 files changed

Lines changed: 342 additions & 314 deletions

CxxTestRegistration/src/regs11_StringConst.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ namespace regs11::type0 {
5252
.methodConst<std::string>(cxx::type::StrConst::fn::reverseString::id)
5353
.build(&StrConst::reverseString));
5454

55-
fns.push_back(rtl::type().member<StrConst>()
55+
/* GCC here fails to automatically resolve the correct overloaded functor
56+
when both a lvalue reference and an rvalue overload exist.
57+
To disambiguate, explicitly cast the member function pointer.
58+
*/ fns.push_back(rtl::type().member<StrConst>()
5659
.methodConst<std::string &>(cxx::type::StrConst::fn::reverseString::id)
5760
.build(static_cast<std::string(StrConst::*)(std::string&) const>(&StrConst::reverseString)));
5861

CxxTestUtils/inc/GlobalTestUtils.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@ namespace test_utils {
1313
static constexpr double g_real = 3.92;
1414
static constexpr double g_imaginary = 9.27;
1515

16-
static constexpr const char* STRA = "ReflectC++";
17-
static constexpr const char* STRA_REVERSE = "++CtcelfeR";
16+
inline constexpr std::string_view STRA = "ReflectC++";
17+
inline constexpr std::string_view STRA_REVERSE = "++CtcelfeR";
1818

19-
static constexpr const char* STRB = "cxxReflection";
20-
static constexpr const char* STRB_REVERSE = "noitcelfeRxxc";
19+
inline constexpr std::string_view STRB = "cxxReflection";
20+
inline constexpr std::string_view STRB_REVERSE = "noitcelfeRxxc";
2121

22-
static constexpr const char* str_reverseString = "reverseString";
23-
static constexpr const char* str_revStrConstRefArg = "revStrConstRefArg";
24-
static constexpr const char* str_revStrRValueRefArg = "revStrRValueRefArg";
25-
static constexpr const char* str_revStrNonConstRefArg = "revStrNonConstRefArg";
26-
static constexpr const char* str_revStrOverloadValRef = "revStrOverloadValRef";
27-
static constexpr const char* str_revStrOverloadValCRef = "revStrOverloadValCRef";
28-
static constexpr const char* str_revStrOverloadValRefAndCRef = "revStrOverloadRefAndCRef";
22+
inline constexpr std::string_view str_reverseString = "reverseString";
23+
inline constexpr std::string_view str_revStrConstRefArg = "revStrConstRefArg";
24+
inline constexpr std::string_view str_revStrRValueRefArg = "revStrRValueRefArg";
25+
inline constexpr std::string_view str_revStrNonConstRefArg = "revStrNonConstRefArg";
26+
inline constexpr std::string_view str_revStrOverloadValRef = "revStrOverloadValRef";
27+
inline constexpr std::string_view str_revStrOverloadValCRef = "revStrOverloadValCRef";
2928

30-
static constexpr const char* str_getComplexNumAsString = "getComplexNumAsString";
29+
inline constexpr std::string_view str_getComplexNumAsString = "getComplexNumAsString";
3130

32-
static constexpr const char* str_setReal = "complex::setReal";
33-
static constexpr const char* str_setImaginary = "complex::setImaginary";
34-
static constexpr const char* str_getMagnitude = "complex::getMagnitude";
31+
inline constexpr std::string_view str_setReal = "complex::setReal";
32+
inline constexpr std::string_view str_setImaginary = "complex::setImaginary";
33+
inline constexpr std::string_view str_getMagnitude = "complex::getMagnitude";
3534

3635
static const char* SUFFIX_void = "_void";
3736
static const char* SUFFIX_ctor = "_ctor";

CxxTestUtils/inc/TestUtilsAnimal.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ namespace test_utils
2020
static constexpr const int AGE = 0.0;
2121
static constexpr const float WEIGHT = 0.0;
2222
static constexpr const bool IS_MAMMAL = false;
23-
static constexpr const char* NAME = "Orangutan";
24-
static constexpr const char* FAMILY_NAME = "Great Ape";
25-
static constexpr const char* ZOO_KEEPER = "Donald McAdams";
26-
27-
static constexpr const char* class_ = "Animal";
28-
static constexpr const char* str_updateZooKeeper = "updateZooKeeper";
29-
static constexpr const char* str_setAnimalName = "setAnimalName";
30-
static constexpr const char* str_setFamilyName = "setFamilyName";
31-
static constexpr const char* str_getFamilyName = "getFamilyName";
23+
static constexpr std::string_view NAME = "Orangutan";
24+
static constexpr std::string_view FAMILY_NAME = "Great Ape";
25+
static constexpr std::string_view ZOO_KEEPER = "Donald McAdams";
26+
27+
static constexpr std::string_view class_ = "Animal";
28+
static constexpr std::string_view str_updateZooKeeper = "updateZooKeeper";
29+
static constexpr std::string_view str_setAnimalName = "setAnimalName";
30+
static constexpr std::string_view str_setFamilyName = "setFamilyName";
31+
static constexpr std::string_view str_getFamilyName = "getFamilyName";
3232

3333
static const bool assert_zero_instance_count();
3434

CxxTestUtils/inc/TestUtilsBook.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ namespace test_utils
1616
{
1717
struct library
1818
{
19-
static constexpr const char* class_ = "Library";
20-
static constexpr const char* str_addBook = "addBook";
21-
static constexpr const char* str_getBookByTitle = "getBookByTitle";
19+
static constexpr std::string_view class_ = "Library";
20+
static constexpr std::string_view str_addBook = "addBook";
21+
static constexpr std::string_view str_getBookByTitle = "getBookByTitle";
2222

2323
static const bool assert_zero_instance_count();
2424
};
2525

2626
struct book
2727
{
2828
static constexpr const double PRICE = 99.923;
29-
static constexpr const char* TITLE = "Somehow, I manage.";
30-
static constexpr const char* AUTHOR = "Micheal G. Scott";
31-
static constexpr const char* DESCRIPTION = "World's greatest boss Michael G. Scott, Regional Manager, shares his wisdom with you.";
32-
static constexpr const char* COPYRIGHT_TAG = "Copyright (c) Micheal Scott Paper Company Pvt. Ltd.";
33-
static constexpr const char* PREFACE = "This is a preface.";
34-
static constexpr const char* ACKNOWLEDGEMENTS = "This is an acknowledgement.";
29+
static constexpr std::string_view TITLE = "Somehow, I manage.";
30+
static constexpr std::string_view AUTHOR = "Micheal G. Scott";
31+
static constexpr std::string_view DESCRIPTION = "World's greatest boss Michael G. Scott, Regional Manager, shares his wisdom with you.";
32+
static constexpr std::string_view COPYRIGHT_TAG = "Copyright (c) Micheal Scott Paper Company Pvt. Ltd.";
33+
static constexpr std::string_view PREFACE = "This is a preface.";
34+
static constexpr std::string_view ACKNOWLEDGEMENTS = "This is an acknowledgement.";
3535

3636
static const int get_book_instance_count();
3737

CxxTestUtils/inc/TestUtilsDate.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace test_utils
1515
{
1616
struct event
1717
{
18-
static constexpr const char* struct_ = "nsdate::Event";
19-
static constexpr const char* str_getDate = "getDate";
20-
static constexpr const char* str_reset = "reset";
18+
static constexpr std::string_view struct_ = "nsdate::Event";
19+
static constexpr std::string_view str_getDate = "getDate";
20+
static constexpr std::string_view str_reset = "reset";
2121

2222
static const bool assert_zero_instance_count();
2323
static const std::size_t get_instance_count();
@@ -36,8 +36,8 @@ namespace test_utils
3636
static constexpr const unsigned DAY = 1;
3737
static constexpr const unsigned MONTH = 1;
3838
static constexpr const unsigned YEAR = 2000;
39-
static constexpr const char* DATE_STR0 = "23/12/2024";
40-
static constexpr const char* DATE_STR1 = "04/05/2025";
39+
static constexpr std::string_view DATE_STR0 = "23/12/2024";
40+
static constexpr std::string_view DATE_STR1 = "04/05/2025";
4141

4242
static const std::size_t get_instance_count();
4343

CxxTestUtils/inc/TestUtilsPerson.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ namespace test_utils
1717
struct person
1818
{
1919
static constexpr const std::size_t AGE = 34;
20-
static constexpr const char* FIRST_NAME = "Sherlock";
21-
static constexpr const char* LAST_NAME = "Holmes";
22-
static constexpr const char* ADDRESS = "221B Baker Street.";
23-
static constexpr const char* OCCUPATION = "Private Detective.";
24-
25-
static constexpr const char* class_ = "Person";
26-
static constexpr const char* str_createPtr = "createPtr";
27-
static constexpr const char* str_getProfile = "getProfile";
28-
static constexpr const char* str_createConst = "createConst";
29-
static constexpr const char* str_getDefaults = "getDefaults";
30-
static constexpr const char* str_getFirstName = "getFirstName";
31-
static constexpr const char* str_updateAddress = "updateAddress";
32-
static constexpr const char* str_updateLastName = "updateLastName";
20+
static constexpr std::string_view FIRST_NAME = "Sherlock";
21+
static constexpr std::string_view LAST_NAME = "Holmes";
22+
static constexpr std::string_view ADDRESS = "221B Baker Street.";
23+
static constexpr std::string_view OCCUPATION = "Private Detective.";
24+
25+
static constexpr std::string_view class_ = "Person";
26+
static constexpr std::string_view str_createPtr = "createPtr";
27+
static constexpr std::string_view str_getProfile = "getProfile";
28+
static constexpr std::string_view str_createConst = "createConst";
29+
static constexpr std::string_view str_getDefaults = "getDefaults";
30+
static constexpr std::string_view str_getFirstName = "getFirstName";
31+
static constexpr std::string_view str_updateAddress = "updateAddress";
32+
static constexpr std::string_view str_updateLastName = "updateLastName";
3333

3434
static const bool assert_zero_instance_count();
3535

CxxTestUtils/src/TestUtilsAnimal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ const bool test_utils::animal::assert_zero_instance_count()
1616
template<>
1717
const bool test_utils::animal::test_method_updateZooKeeper<std::string&>(const std::string& pZooKeeper)
1818
{
19-
std::string zooKeeper = ZOO_KEEPER;
19+
std::string zooKeeper(ZOO_KEEPER);
2020
return (pZooKeeper == Animal::updateZooKeeper(zooKeeper));
2121
}
2222

2323

2424
template<>
2525
const bool test_utils::animal::test_method_updateZooKeeper<std::string&&>(const std::string& pZooKeeper)
2626
{
27-
return (pZooKeeper == Animal::updateZooKeeper(ZOO_KEEPER));
27+
return (pZooKeeper == Animal::updateZooKeeper(std::string(ZOO_KEEPER)));
2828
}
2929

3030

3131
template<>
3232
const bool test_utils::animal::test_method_updateZooKeeper<const std::string&>(const std::string& pZooKeeper)
3333
{
34-
const std::string zooKeeper = ZOO_KEEPER;
34+
const std::string zooKeeper(ZOO_KEEPER);
3535
return (pZooKeeper == Animal::updateZooKeeper(zooKeeper));
3636
}
3737

CxxTestUtils/src/TestUtilsBook.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace test_utils
5353
if (pInstance.canViewAs<Book>())
5454
{
5555
const auto& rbook = pInstance.view<Book>()->get();
56-
return (Book(PRICE, TITLE) == rbook);
56+
return (Book(PRICE, std::string(TITLE)) == rbook);
5757
}
5858
return false;
5959
}
@@ -64,7 +64,7 @@ namespace test_utils
6464
if (pInstance.canViewAs<Book>())
6565
{
6666
Book book;
67-
book.setAuthor(AUTHOR);
67+
book.setAuthor(AUTHOR.data());
6868
const auto& rbook = pInstance.view<Book>()->get();
6969
return (book == rbook);
7070
}
@@ -76,7 +76,7 @@ namespace test_utils
7676
if (pInstance.canViewAs<Book>())
7777
{
7878
Book book;
79-
book.addCopyrightTag(COPYRIGHT_TAG);
79+
book.addCopyrightTag(std::string(COPYRIGHT_TAG));
8080
const auto& rbook = pInstance.view<Book>()->get();
8181
return (book == rbook);
8282
}
@@ -89,7 +89,7 @@ namespace test_utils
8989
if (pInstance.canViewAs<Book>())
9090
{
9191
Book book;
92-
book.addPreface(ACKNOWLEDGEMENTS, PREFACE);
92+
book.addPreface(std::string(ACKNOWLEDGEMENTS), std::string(PREFACE));
9393
const auto& rbook = pInstance.view<Book>()->get();
9494
return (book == rbook);
9595
}
@@ -117,7 +117,7 @@ namespace test_utils
117117
if (pInstance.canViewAs<Book>())
118118
{
119119
Book book;
120-
book.updateBookInfo(TITLE, PRICE, string(AUTHOR));
120+
book.updateBookInfo(TITLE.data(), PRICE, string(AUTHOR));
121121
const auto& rbook = pInstance.view<Book>()->get();
122122
return (book == rbook);
123123
}
@@ -131,7 +131,7 @@ namespace test_utils
131131
if (pInstance.canViewAs<Book>())
132132
{
133133
Book book;
134-
book.updateBookInfo(string(AUTHOR), PRICE, TITLE);
134+
book.updateBookInfo(string(AUTHOR), PRICE, TITLE.data());
135135
const auto& rbook = pInstance.view<Book>()->get();
136136
return (book == rbook);
137137
}
@@ -143,9 +143,9 @@ namespace test_utils
143143
{
144144
if (pInstance.canViewAs<Book>())
145145
{
146-
Book obj(PRICE, TITLE);
147-
obj.setAuthor(AUTHOR);
148-
obj.setDescription(DESCRIPTION);
146+
Book obj(PRICE, std::string(TITLE));
147+
obj.setAuthor(std::string(AUTHOR));
148+
obj.setDescription(std::string(DESCRIPTION));
149149
Book copyObj(obj);
150150
const auto& rbook = pInstance.view<Book>()->get();
151151
return (copyObj == rbook);

CxxTestUtils/src/TestUtilsDate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace test_utils
7171
{
7272
if (pInstance.canViewAs<Date>()) {
7373
const Date& rdate = pInstance.view<Date>()->get();
74-
return (Date(DATE_STR0) == rdate);
74+
return (Date(std::string(DATE_STR0)) == rdate);
7575
}
7676
return false;
7777
}

CxxTestUtils/src/TestUtilsPerson.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@ namespace test_utils
3838
template<>
3939
const std::string person::get_str_returned_on_call_getProfile<string, size_t>(const bool pNoAddress)
4040
{
41-
return Person::getProfile(OCCUPATION, AGE);
41+
return Person::getProfile(std::string(OCCUPATION), AGE);
4242
}
4343

4444

4545
const bool person::test_method_updateLastName_const(const rtl::RObject& pInstance)
4646
{
4747
if (pInstance.canViewAs<Person>())
4848
{
49-
const Person person(FIRST_NAME);
50-
person.updateLastName(LAST_NAME);
49+
auto lastName = std::string(LAST_NAME);
50+
auto firstName = std::string(FIRST_NAME);
51+
52+
const Person person(firstName);
53+
person.updateLastName(lastName);
54+
5155
const Person& rPerson = pInstance.view<Person>()->get();
5256
return (person == rPerson);
5357
}
@@ -61,8 +65,11 @@ namespace test_utils
6165
{
6266
if (pInstance.canViewAs<Person>())
6367
{
64-
Person person(FIRST_NAME);
65-
person.updateAddress(ADDRESS);
68+
auto address = std::string(ADDRESS);
69+
auto firstName = std::string(FIRST_NAME);
70+
71+
Person person(firstName);
72+
person.updateAddress(address);
6673
const Person& rPerson = pInstance.view<Person>()->get();
6774
return (person == rPerson);
6875
}
@@ -87,8 +94,11 @@ namespace test_utils
8794
{
8895
if (pInstance.canViewAs<Person>())
8996
{
90-
const Person person(FIRST_NAME);
91-
person.updateAddress(ADDRESS);
97+
auto address = std::string(ADDRESS);
98+
auto firstName = std::string(FIRST_NAME);
99+
100+
const Person person(firstName);
101+
person.updateAddress(address);
92102
const Person& rPerson = pInstance.view<Person>()->get();
93103
return (person == rPerson);
94104
}
@@ -101,7 +111,9 @@ namespace test_utils
101111
{
102112
if (pInstance.canViewAs<Person>())
103113
{
104-
Person person(FIRST_NAME);
114+
auto firstName = std::string(FIRST_NAME);
115+
116+
Person person(firstName);
105117
person.updateAddress();
106118
const Person& rPerson = pInstance.view<Person>()->get();
107119
return (person == rPerson);
@@ -115,7 +127,9 @@ namespace test_utils
115127
{
116128
if (pInstance.canViewAs<Person>())
117129
{
118-
const Person person(FIRST_NAME);
130+
auto firstName = std::string(FIRST_NAME);
131+
132+
const Person person(firstName);
119133
person.updateAddress();
120134
const Person& rPerson = pInstance.view<Person>()->get();
121135
return (person == rPerson);

0 commit comments

Comments
 (0)