Print expressions in error messages

This commit is contained in:
Marek Polacek
2026-01-12 15:12:58 -05:00
parent e3016c2b34
commit 8abe9fca3c
7 changed files with 30 additions and 29 deletions

View File

@@ -8396,16 +8396,16 @@ check_splice_expr (location_t loc, location_t start_loc, tree t,
&& (DECL_CONSTRUCTOR_P (t) || DECL_DESTRUCTOR_P (t)))
{
if (complain_p)
error_at (loc, "cannot use constructor or destructor in a splice "
"expression");
error_at (loc, "cannot use constructor or destructor %qD in a splice "
"expression", t);
return false;
}
/* -- an unnamed bit-field */
if (TREE_CODE (t) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (t))
{
if (complain_p)
error_at (loc, "cannot use an unnamed bit-field in a splice "
"expression");
error_at (loc, "cannot use an unnamed bit-field %qD in a splice "
"expression", t);
return false;
}
/* Class members may not be implicitly referenced through a splice.
@@ -8417,8 +8417,8 @@ check_splice_expr (location_t loc, location_t start_loc, tree t,
|| (VAR_P (t) && DECL_ANON_UNION_VAR_P (t))))
{
if (complain_p)
error_at (loc, "cannot implicitly reference a class member through "
"a splice");
error_at (loc, "cannot implicitly reference a class member %qD "
"through a splice", t);
return false;
}
/* [expr.unary.op]/3.1 "If the operand [of unary &] is a qualified-id or
@@ -8459,7 +8459,8 @@ check_splice_expr (location_t loc, location_t start_loc, tree t,
if (TREE_CODE (t) == TREE_LIST && annotation_p (t))
{
if (complain_p)
error_at (loc, "cannot use an annotation in a splice expression");
error_at (loc, "cannot use an annotation %qE in a splice expression",
t);
return false;
}

View File

@@ -3,12 +3,12 @@
static union { int m; };
constexpr auto r = ^^m;
auto p = [:r:]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto p = [:r:]; // { dg-error "cannot implicitly reference a class member .m. through a splice" }
namespace N {
static union { int mn; };
constexpr auto rn = ^^mn;
auto pn = [:rn:]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto pn = [:rn:]; // { dg-error "cannot implicitly reference a class member .mn. through a splice" }
}
struct S {
@@ -17,7 +17,7 @@ struct S {
};
};
constexpr auto p2 = [: ^^S::m :]; // { dg-error "cannot implicitly reference a class member through a splice" }
constexpr auto p2 = [: ^^S::m :]; // { dg-error "cannot implicitly reference a class member .S::<unnamed union>::m. through a splice" }
void
f ()
@@ -25,19 +25,19 @@ f ()
static union {
int x;
};
auto rx = [: ^^x :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto rx = [: ^^x :]; // { dg-error "cannot implicitly reference a class member .x. through a splice" }
union {
union {
int u;
};
};
auto ru = [: ^^u :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto ru = [: ^^u :]; // { dg-error "cannot implicitly reference a class member .u. through a splice" }
struct L {
union {
int z;
};
};
auto rz = [: ^^L::z :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto rz = [: ^^L::z :]; // { dg-error "cannot implicitly reference a class member .f\\(\\)::L::<unnamed union>::z. through a splice" }
}

View File

@@ -14,6 +14,6 @@ g ()
constexpr auto r2 = ^^A::A(); // { dg-error "cannot take the reflection of an overload set" }
constexpr auto r3 = ^^A::A::A; // { dg-error "cannot take the reflection of an overload set" }
constexpr auto r4 = ^^A::~A;
[: r4 :]; // { dg-error "cannot use constructor or destructor in a splice expression" }
[: ^^A::~A :]; // { dg-error "cannot use constructor or destructor in a splice expression" }
[: r4 :]; // { dg-error "cannot use constructor or destructor .A::~A\\(\\). in a splice expression" }
[: ^^A::~A :]; // { dg-error "cannot use constructor or destructor .A::~A\\(\\). in a splice expression" }
}

View File

@@ -13,7 +13,7 @@ struct S {
auto p = &[: ^^S::m :];
auto q = &[: ^^S::m :];
auto rm = [: ^^S::m :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto rn = [: ^^S::n :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto re = [: ^^S::e :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto ra = [: ^^S::a :]; // { dg-error "cannot implicitly reference a class member through a splice" }
auto rm = [: ^^S::m :]; // { dg-error "cannot implicitly reference a class member .int S::m\\(this S\\). through a splice" }
auto rn = [: ^^S::n :]; // { dg-error "cannot implicitly reference a class member .int S::n\\(\\) const. through a splice" }
auto re = [: ^^S::e :]; // { dg-error "cannot implicitly reference a class member .S::e. through a splice" }
auto ra = [: ^^S::a :]; // { dg-error "cannot implicitly reference a class member .S::a. through a splice" }

View File

@@ -9,5 +9,5 @@ constexpr auto r = ^^S::i;
/* A pointer to member is only formed when an explicit & is used and
its operand is a qualified-id or splice-expression not enclosed in
parentheses. */
auto p = &([: r :]); // { dg-error "cannot implicitly reference a class member through a splice" }
auto p = &([: r :]); // { dg-error "cannot implicitly reference a class member .S::i. through a splice" }
auto q = &[: r :];

View File

@@ -25,15 +25,15 @@ g ()
constexpr auto r2 = ^^B<int>::x; // { dg-error "private within this context" }
constexpr auto r3 = ^^C::x;
int i1 = [: r3 :]; // { dg-error "cannot implicitly reference a class member through a splice" }
[: r3 :]; // { dg-error "cannot implicitly reference a class member through a splice" }
[: r3 :] = 0; // { dg-error "cannot implicitly reference a class member through a splice" }
int i1 = [: r3 :]; // { dg-error "cannot implicitly reference a class member .C::x. through a splice" }
[: r3 :]; // { dg-error "cannot implicitly reference a class member .C::x. through a splice" }
[: r3 :] = 0; // { dg-error "cannot implicitly reference a class member .C::x. through a splice" }
constexpr auto r4 = ^^foo; // { dg-error "reflection of an overload set" }
constexpr auto r5 = ^^bar; // { dg-error "reflection of an overload set" }
constexpr auto r6 = ^^D::x; // { dg-error "expected" }
constexpr auto r7 = ^^D<int>::x;
[: r7 :]; // { dg-error "cannot implicitly reference a class member through a splice" }
[: r7 :]; // { dg-error "cannot implicitly reference a class member .D<int>::x. through a splice" }
}
void

View File

@@ -18,11 +18,11 @@ foo ()
{
S s = { 0 }, t = { 0 };
constexpr auto ctx = access_context::unchecked ();
s.[: members_of (^^S, ctx)[1] :] = 1; // { dg-error "cannot use an unnamed bit-field in a splice expression" }
s.[: (members_of (^^S, ctx) | std::views::filter (is_default_constructor) | std::ranges::to <std::vector> ())[0] :] (); // { dg-error "cannot use constructor or destructor in a splice expression" }
s.[: (members_of (^^S, ctx) | std::views::filter (is_copy_constructor) | std::ranges::to <std::vector> ())[0] :] (t); // { dg-error "cannot use constructor or destructor in a splice expression" }
s.[: (members_of (^^S, ctx) | std::views::filter (is_destructor) | std::ranges::to <std::vector> ())[0] :] (); // { dg-error "cannot use constructor or destructor in a splice expression" }
[: annotations_of (^^foo)[0] :]; // { dg-error "cannot use an annotation in a splice expression" }
s.[: members_of (^^S, ctx)[1] :] = 1; // { dg-error "cannot use an unnamed bit-field .S::<anonymous>. in a splice expression" }
s.[: (members_of (^^S, ctx) | std::views::filter (is_default_constructor) | std::ranges::to <std::vector> ())[0] :] (); // { dg-error "cannot use constructor or destructor .constexpr S::S\\(\\). in a splice expression" }
s.[: (members_of (^^S, ctx) | std::views::filter (is_copy_constructor) | std::ranges::to <std::vector> ())[0] :] (t); // { dg-error "cannot use constructor or destructor .constexpr S::S\\(const S&\\). in a splice expression" }
s.[: (members_of (^^S, ctx) | std::views::filter (is_destructor) | std::ranges::to <std::vector> ())[0] :] (); // { dg-error "cannot use constructor or destructor .constexpr S::~S\\(\\). in a splice expression" }
[: annotations_of (^^foo)[0] :]; // { dg-error "cannot use an annotation .1. in a splice expression" }
[: data_member_spec (^^S, { .name = "name" }) :]; // { dg-error "cannot use a data member specification in a splice expression" }
[: bases_of (^^T, ctx)[0] :]; // { dg-error "" "" { xfail *-*-* } }
}