Date: Fri, 06 Mar 2026 02:06:55 +0000
Hello,
I was wondering what the proper behavior of the following code should be:
#include <meta>
[[=1]]
void function();
static_assert(annotations_of(^^function).size() == 1);
template<auto Value>
consteval void annotate_function() {
[[=Value]]
void function();
}
consteval {
annotate_function<2>();
}
int main() {
static constexpr auto NumAnnotations = annotations_of(^^function).size();
std::printf("Annotation count: %zu", NumAnnotations);
}
Godbolt link: https://godbolt.org/z/4dca5xEPe
With GCC trunk, it prints "Annotation count: 1", but with the experimental Clang reflection branch it prints "Annotation count: 3". I assume Clang here is acting erroneously in some regard because it appears to be duplicating the initial annotation placed on the function. But what I'm more interested in is whether the compiler should be appending the annotation from annotate_function globally.
As well, if one removes the templating from annotate_function, GCC continues to report only one annotation, but Clang reports two: https://godbolt.org/z/74evKWT3a
I'd also be interested in how that is meant to behave.
Thanks
I was wondering what the proper behavior of the following code should be:
#include <meta>
[[=1]]
void function();
static_assert(annotations_of(^^function).size() == 1);
template<auto Value>
consteval void annotate_function() {
[[=Value]]
void function();
}
consteval {
annotate_function<2>();
}
int main() {
static constexpr auto NumAnnotations = annotations_of(^^function).size();
std::printf("Annotation count: %zu", NumAnnotations);
}
Godbolt link: https://godbolt.org/z/4dca5xEPe
With GCC trunk, it prints "Annotation count: 1", but with the experimental Clang reflection branch it prints "Annotation count: 3". I assume Clang here is acting erroneously in some regard because it appears to be duplicating the initial annotation placed on the function. But what I'm more interested in is whether the compiler should be appending the annotation from annotate_function globally.
As well, if one removes the templating from annotate_function, GCC continues to report only one annotation, but Clang reports two: https://godbolt.org/z/74evKWT3a
I'd also be interested in how that is meant to behave.
Thanks
Received on 2026-03-06 02:07:06
