Re: [PATCH] c++: Improve printing of null pointer to data member constants [PR126599]
Jakub Jelinek <[email protected]> Tue, 4 Aug 2026 18:49:31 +0200
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <anIYG7fjWLRvI90t@tucnak> |
On Tue, Aug 04, 2026 at 12:28:06PM -0400, Jason Merrill wrote:
> > + if (TYPE_PTRDATAMEM_P (TREE_TYPE (t)) && integer_all_onesp (t))
> > + {
> > + /* OFFSET_TYPE -1 is a null pointer to member. */
> > + if (flags & TFF_EXPR_IN_PARENS)
> > + pp_cxx_left_paren (pp);
> > + pp_cxx_left_paren (pp);
> > + dump_type (pp, TREE_TYPE (t), flags);
> > + pp_cxx_right_paren (pp);
> > + pp->constant (cxx_dialect < cxx11 ? null_pointer_node : nullptr_node);
>
> It looks like you don't test the C++98 case.
Yeah, I haven't figured out how to force printing %qE with that value in
C++98. Tried various things, like:
struct S { int s; };
struct U { int u; };
template <int A> struct T {};
T<(int S::*) 0> t;
const int S::*p = ((int S::*) 0) + 4;
S s = ((int S::*) 0);
const int v = ((int S::*) 0) == ((int U::*) 0);
but nothing printed it.
I can reproduce it with
struct A { int a; };
struct __attribute__((strub ((int A::*) 0))) B {};
though (without patch):
~/src/gcc/obj84/gcc/cc1plus -quiet a3.C -std=c++98
a3.C:2:46: warning: ignoring attribute ‘strub’ because of excess arguments starting at ‘-1’ [-Wattributes]
2 | struct __attribute__((strub ((int A::*) 0))) B {};
| ^
a3.C:2:46: warning: attribute ‘strub’ does not apply to fields of aggregate type ‘B’ [-Wattributes]
vs. (with patch):
~/src/gcc/obj86/gcc/cc1plus -quiet a3.C -std=c++98
a3.C:2:46: warning: ignoring attribute ‘strub’ because of excess arguments starting at ‘(int A::*)0’ [-Wattributes]
2 | struct __attribute__((strub ((int A::*) 0))) B {};
| ^
a3.C:2:46: warning: attribute ‘strub’ does not apply to fields of aggregate type ‘B’ [-Wattributes]
Shall I include that in the testsuite even when it just looks that
the strub attribute diagnostics probably should be improved?
Jakub