Skip to content

Commit

Permalink
tests for extract
Browse files Browse the repository at this point in the history
Signed-off-by: Valentyn Yukhymenko <[email protected]>
  • Loading branch information
BaLiKfromUA committed Nov 8, 2024
1 parent d0cc375 commit f6e7c78
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// [reflection]

#include <experimental/meta>
#include <utility>

class A {
public:
Expand All @@ -27,6 +28,8 @@ class A {
const int a = 42;
};

enum Enum { Value = 42 };

int main() {
constexpr int i = 1;
int non_constexpr_i = 42;
Expand Down Expand Up @@ -77,4 +80,30 @@ int main() {
object_of(^^::);
// expected-error@-1 {{call to consteval function 'std::meta::object_of' is not a constant expression}}
// expected-note-re@-2 {{cannot query the object of {{.*}}}}

// ==============
// extract
// ==============
extract<int>(^^i); // ok

extract<A>(^^i);
// expected-error@-1 {{call to consteval function 'std::meta::extract<A>' is not a constant expression}}
// expected-note-re@-2 {{reflected value of type {{.*}} cannot be extracted as a value of type {{.*}}}}}

const auto [x, y] = std::pair{1, 2};
extract<int>(^^x);
// expected-error@-1 {{call to consteval function 'std::meta::extract<int>' is not a constant expression}}
// expected-note@-2 {{extraction from a reflection of a structured binding is not allowed}}

extract<int>(^^::);
// expected-error@-1 {{call to consteval function 'std::meta::extract<int>' is not a constant expression}}
// expected-note-re@-2 {{cannot extract a value from a reflection of {{.*}}}}

extract<int>(object_of(^^obj));
// expected-error@-1 {{call to consteval function 'std::meta::extract<int>' is not a constant expression}}
// expected-note-re@-2 {{reflected object of type {{.*}} cannot be extracted as a value of type {{.*}}}}}

extract<A>(^^Enum::Value);
// expected-error@-1 {{call to consteval function 'std::meta::extract<A>' is not a constant expression}}
// expected-note-re@-2 {{reflected enum constant of type {{.*}} cannot be extracted as a value of type {{.*}}}}}
}

0 comments on commit f6e7c78

Please sign in to comment.