t = dtor;
}
- /* Look through block scope externs. */
+ /* Block-scope externs are invalid here as per the proposed resolution
+ of CWG 3065. */
if (VAR_OR_FUNCTION_DECL_P (t) && DECL_LOCAL_DECL_P (t))
- t = DECL_LOCAL_DECL_ALIAS (t);
+ {
+ error_at (loc, "cannot take the reflection of a block-scope extern %qE",
+ t);
+ return error_mark_node;
+ }
if (t == error_mark_node)
return error_mark_node;
--- /dev/null
+// PR c++/124756
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+template<typename T>
+consteval void
+f0 ()
+{
+ void fun(T);
+ auto _ = ^^fun; // { dg-error "cannot take the reflection of a block-scope extern .fun." }
+ extern int arr[3];
+ auto _ = ^^arr; // { dg-error "cannot take the reflection of a block-scope extern .arr." }
+ extern int e;
+ auto _ = ^^e; // { dg-error "cannot take the reflection of a block-scope extern .e." }
+}
+
+consteval {
+ f0<int>();
+}
+
+consteval void
+f1 ()
+{
+ void fun(int);
+ auto _ = ^^fun; // { dg-error "cannot take the reflection of a block-scope extern .fun." }
+ extern int arr[3];
+ auto _ = ^^arr; // { dg-error "cannot take the reflection of a block-scope extern .arr." }
+ extern int e;
+ auto _ = ^^e; // { dg-error "cannot take the reflection of a block-scope extern .e." }
+}
// Test std::meta::identifier_of.
#include <meta>
+using namespace std::meta;
void foo (int, int x, int y, int z);
void foo (int w, int, int v, int z);
int bar (int, int, int v, int z, int u);
void qux (int, int x, int y, int z);
- constexpr auto qux1 = parameters_of (^^qux)[0];
- constexpr auto qux2 = parameters_of (^^qux)[1];
- constexpr auto qux3 = parameters_of (^^qux)[2];
- constexpr auto qux4 = parameters_of (^^qux)[3];
+ constexpr auto qux1 = parameters_of (^^qux)[0]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
+ constexpr auto qux2 = parameters_of (^^qux)[1]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
+ constexpr auto qux3 = parameters_of (^^qux)[2]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
+ constexpr auto qux4 = parameters_of (^^qux)[3]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
static_assert (!has_identifier (qux1));
static_assert (identifier_of (qux2) == std::string_view ("x"));
static_assert (identifier_of (qux3) == std::string_view ("y"));
fred ()
{
void qux (int w, int, int v, int z);
- constexpr auto qux1 = parameters_of (^^qux)[0];
- constexpr auto qux2 = parameters_of (^^qux)[1];
- constexpr auto qux3 = parameters_of (^^qux)[2];
- constexpr auto qux4 = parameters_of (^^qux)[3];
+ constexpr auto qux1 = parameters_of (^^qux)[0]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
+ constexpr auto qux2 = parameters_of (^^qux)[1]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
+ constexpr auto qux3 = parameters_of (^^qux)[2]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
+ constexpr auto qux4 = parameters_of (^^qux)[3]; // { dg-error "cannot take the reflection of a block-scope extern .qux." }
static_assert (identifier_of (qux1) == std::string_view ("w"));
static_assert (identifier_of (qux2) == std::string_view ("x"));
static_assert (!has_identifier (qux3));
// { dg-additional-options "-freflection" }
#include <meta>
+using namespace std::meta;
int a;
extern int b;
bar ()
{
extern int a;
- return ^^a;
+ return ^^a; // { dg-error "cannot take the reflection of a block-scope extern .a." }
}
consteval auto
baz ()
{
extern int b;
- return ^^b;
+ return ^^b; // { dg-error "cannot take the reflection of a block-scope extern .b." }
}
consteval auto
static_assert (has_default_argument (parameters_of (^^foo)[2]));
{
extern int foo (int x, int y = 5, int z = 16);
- static_assert (!has_default_argument (parameters_of (^^foo)[0]));
- static_assert (has_default_argument (parameters_of (^^foo)[1]));
- static_assert (has_default_argument (parameters_of (^^foo)[2]));
- return ^^foo;
+ static_assert (!has_default_argument (parameters_of (^^foo)[0])); // { dg-error "cannot take the reflection of a block-scope extern .foo." }
+ static_assert (has_default_argument (parameters_of (^^foo)[1])); // { dg-error "cannot take the reflection of a block-scope extern .foo." }
+ static_assert (has_default_argument (parameters_of (^^foo)[2])); // { dg-error "cannot take the reflection of a block-scope extern .foo." }
+ return ^^foo; // { dg-error "cannot take the reflection of a block-scope extern .foo." }
}
}