Skip to content

Commit c09329e

Browse files
committed
fix: Drop the anonymous namespace from the benchmark URI
The namespace was extracted from __PRETTY_FUNCTION__ and rejected only when spelled '(anonymous namespace)', as clang does, so with GCC, which spells it '{anonymous}', it ended up in the URI: file.cpp::{anonymous}::bench[…]. Strip the segment instead of bailing out, for both spellings, so the rest of the namespace path is kept and no error is reported for a construct that is merely unnameable.
1 parent 76985b6 commit c09329e

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

core/src/uri.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
#include <iostream>
21
#include <string>
32

43
#include "codspeed.h"
54

65
namespace codspeed {
76

7+
// The anonymous namespace is not a part of any identifier the benchmark can be referred to by,
8+
// and its spelling differs between the compilers, so it is dropped from the namespace path.
9+
// Example: {anonymous}::outer:: (GCC) or (anonymous namespace)::outer:: (clang)
10+
// Returns: outer::
11+
std::string strip_anonymous_namespace(std::string ns) {
12+
for (const std::string anon : {"{anonymous}::", "(anonymous namespace)::"}) {
13+
for (auto pos = ns.find(anon); pos != std::string::npos; pos = ns.find(anon)) {
14+
ns.erase(pos, anon.size());
15+
}
16+
}
17+
return ns;
18+
}
19+
820
// Example: auto outer::test12::(anonymous class)::operator()() const
921
// Returns: outer::test12::
1022
std::string extract_namespace_clang(const std::string &pretty_func) {
@@ -36,16 +48,10 @@ std::string extract_namespace_gcc(const std::string &pretty_func) {
3648
// Returns: An empty string if the namespace could not be extracted,
3749
// otherwise the namespace with a trailing "::"
3850
std::string extract_lambda_namespace(const std::string &pretty_func) {
39-
if (pretty_func.find("(anonymous namespace)") != std::string::npos) {
40-
std::cerr << "[ERROR] Anonymous namespace not supported in " << pretty_func
41-
<< std::endl;
42-
return {};
43-
}
44-
4551
#ifdef __clang__
46-
return extract_namespace_clang(pretty_func);
52+
return strip_anonymous_namespace(extract_namespace_clang(pretty_func));
4753
#elif __GNUC__
48-
return extract_namespace_gcc(pretty_func);
54+
return strip_anonymous_namespace(extract_namespace_gcc(pretty_func));
4955
#elif _MSC_VER
5056
// MSVC doesn't support __PRETTY_FUNCTION__ in the same way
5157
// Return empty string as fallback for Windows

0 commit comments

Comments
 (0)