Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#6760 closed Bugs (invalid)

PUSH_BACK/_FRONT on empty array broken

Reported by: yves.pausch@… Owned by: pmenso57
Milestone: Boost 1.50.0 Component: preprocessor
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

BOOST_PP_ARRAY_PUSH_BACK & BOOST_PP_ARRAY_PUSH_FRONT on empty array leads to invalid C++ because of unresolved macro

Sample to reproduce this bug:

#define ARRAY (3, (a, b, c)) #define EMPTY_ARRAY (0, ()) BOOST_PP_ARRAY_PUSH_BACK(ARRAY, d) BOOST_PP_ARRAY_PUSH_BACK(EMPTY_ARRAY, d)

brings using 1.48

(4, (a, b, c , d)) (1, ( d))

which is expected and correct

brings using 1.49

(4, (a, b, c , d)) (1, (BOOST_PP_TUPLE_REM_0 () d))

Attachments (1)

boost_pp_ticket_6760.cpp (474 bytes ) - added by yves.pausch@… 11 years ago.
sample to reproduce the problem

Download all attachments as: .zip

Change History (5)

by yves.pausch@…, 11 years ago

Attachment: boost_pp_ticket_6760.cpp added

sample to reproduce the problem

comment:1 by pmenso57, 11 years ago

There is no such thing as a zero-element array or tuple.

(0, ())

should be

(1, ())

because it is a one-element array whose element is nothing--just as with

(2, (,))
(3, (,,))

and so on.

If there was a zero-element array, it would be something like:

(0, ~) // (0,) in >= C99 or >= C++11

but that rogue value would require special handling in all of the array operations that defer to tuple operations.

comment:2 by pmenso57, 11 years ago

Owner: changed from No-Maintainer to pmenso57

comment:3 by pmenso57, 11 years ago

Resolution: invalid
Status: newclosed

comment:4 by frank.richter@…, 11 years ago

The reference docs make no statement about the validity of empty tuples or arrays. Only one place makes an implication: “Sequences are data structures that merge the properties of both lists and tuples with the exception that a seq cannot be empty.” - the implication being that lists and tuples (and thus by extension arrays) _can_ be empty.

So now you stated tuples (and by extension arrays) cannot be empty. Judging from the list documentation, an empty list is not possible, either (as I read it, the tail can be BOOST_PP_NIL, but it's stated the head can only be an element).

So what container _can_ be empty? The documentation doesn't say. And at least until 1.49 and empty array was a working solution. So if you're not planning to provide some support of zero-element tuples/arrays, at the very least consider the whole thing a documentation issue, and that some more explicit words on empty containers would be desireable.

Note: See TracTickets for help on using tickets.