Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions core/foundation/src/TClassEdit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <memory>
#include <string_view>
#include <algorithm>
#include <string>

#include "TSpinLockGuard.h"

Expand Down Expand Up @@ -621,13 +622,19 @@ static size_t findNameEnd(const std::string &full, size_t pos)
bool TClassEdit::IsDefAlloc(const char *allocname, const char *classname)
{
string_view a( allocname );
// In Windows, allocname might be 'class const std::allocator<int>',
// (never 'const class ...'), so we start by stripping the 'class ', if any
constexpr static int clalloclen = std::char_traits<char>::length("class ");
if (a.compare(0,clalloclen,"class ") == 0) {
a.remove_prefix(clalloclen);
}
RemoveStd(a);

if (a=="alloc") return true;
if (a=="__default_alloc_template<true,0>") return true;
if (a=="__malloc_alloc_template<0>") return true;

const static int alloclen = strlen("allocator<");
constexpr static int alloclen = std::char_traits<char>::length("allocator<");
if (a.compare(0,alloclen,"allocator<") != 0) {
return false;
}
Expand Down Expand Up @@ -676,15 +683,15 @@ bool TClassEdit::IsDefAlloc(const char *allocname,
string_view a( allocname );
RemoveStd(a);

const static int alloclen = strlen("allocator<");
constexpr static int alloclen = std::char_traits<char>::length("allocator<");
if (a.compare(0,alloclen,"allocator<") != 0) {
return false;
}
a.remove_prefix(alloclen);

RemoveStd(a);

const static int pairlen = strlen("pair<");
constexpr static int pairlen = std::char_traits<char>::length("pair<");
if (a.compare(0,pairlen,"pair<") != 0) {
return false;
}
Expand Down Expand Up @@ -1533,14 +1540,19 @@ static void ResolveTypedefImpl(const char *tname,
}
while (tname[cursor]==' ') ++cursor;
}

// In Windows, we might have 'class const ...' as name,
// (never 'const class ...'), so skip the leading 'class ', if any
if (tname[cursor]=='c' && (cursor+6<len)) {
if (strncmp(tname+cursor,"class ",6) == 0) {
cursor += 6;
}
}
if (tname[cursor]=='c' && (cursor+6<len)) {
if (strncmp(tname+cursor,"const ",6) == 0) {
cursor += 6;
if (modified) result += "const ";
}
constprefix = true;

}

if (len > 2 && strncmp(tname+cursor,"::",2) == 0) {
Expand Down
14 changes: 14 additions & 0 deletions core/foundation/test/testClassEdit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,17 @@ TEST(TClassEdit, DefComp)
{
EXPECT_FALSE(TClassEdit::IsDefComp("std::less<>", "std::string"));
}

// https://github.com/root-project/root/issues/6607
TEST(TClassEdit, DefAlloc)
{
EXPECT_TRUE(TClassEdit::IsDefAlloc("class std::allocator<float>", "float"));
}

// https://github.com/root-project/root/issues/6607
TEST(TClassEdit, GetNormalizedName)
{
std::string n;
TClassEdit::GetNormalizedName(n, "std::vector<float, class std::allocator<float>>");
EXPECT_STREQ("vector<float>", n.c_str());
}
Loading