Skip to content

fix ListOf compile by not relying on get__() in attribute accessors#1484

Merged
eddelbuettel merged 3 commits into
masterfrom
bugfix/listof-hasattribute-get
Jun 29, 2026
Merged

fix ListOf compile by not relying on get__() in attribute accessors#1484
eddelbuettel merged 3 commits into
masterfrom
bugfix/listof-hasattribute-get

Conversation

@kevinushey

Copy link
Copy Markdown
Contributor

Fixes #1483.

Problem

AttributeProxyPolicy<CLASS> is a policy base class. Its attributeNames() and hasAttribute() members fetched the underlying SEXP via static_cast<const CLASS&>(*this).get__(). But get__() is not part of this policy -- it is provided by the storage policy (PreserveStorage / NoProtectStorage). Vector, XPtr and the macro-generated classes inherit a storage policy, so they have get__(); ListOf<T> inherits AttributeProxyPolicy without a storage policy and has only get() / operator SEXP().

As a result, e.g. RestRserve's x.hasAttribute("names") on a ListOf<...> failed to compile under R >= 4.6.0:

'const class Rcpp::ListOf<Rcpp::Vector<16> >' has no member named 'get__'; did you mean 'get'?

Fix

Drop .get__() and rely on the implicit operator SEXP() conversion that all of these classes provide. This matches the adjacent R_getAttribNames(static_cast<const CLASS&>(*this)) call (which already worked for ListOf) and is equivalent to the pre-4.6.0 .attr() path. Both the R >= 4.6.0 hasAttribute() and the pre-4.6.0 attributeNames() spot are fixed (the latter had the same latent bug for ListOf).

Tests

Added listof_has_attr / listof_attribute_names exports and corresponding cases in test_listof.R. Full test_listof.R passes (20 results).

AttributeProxyPolicy is a base class whose CLASS template parameter
need not provide get__() (that comes from the storage policy). ListOf
inherits AttributeProxyPolicy without a storage policy, so hasAttribute()
and attributeNames() failed to compile for it. Use the operator SEXP()
conversion every such class provides instead, matching the existing
R_getAttribNames() call. Fixes #1483.

@eddelbuettel eddelbuettel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Usual micro nit: ChangeLog entry in two lines, if we can?

@Enchufa2

Copy link
Copy Markdown
Member

In #1464 I already removed a couple of them to rely on SEXP for ListOf, so it only makes sense to do the same here.

@eddelbuettel

Copy link
Copy Markdown
Member

No (new) issues in reverse dependency checks.

@eddelbuettel eddelbuettel merged commit 90d6b45 into master Jun 29, 2026
28 checks passed
@eddelbuettel eddelbuettel deleted the bugfix/listof-hasattribute-get branch June 29, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New issue on get__() versus get()

3 participants