mdspan icon indicating copy to clipboard operation
mdspan copied to clipboard

Build failing on GCC arm due to _N defined as a macro

Open LnnrtS opened this issue 2 years ago • 7 comments

ctype.h on that platform defines

#define	_U	01
#define	_L	02
#define	_N	04
#define	_S	010
#define _P	020
#define _C	040
#define _X	0100
#define	_B	0200

which breaks mdspan in many places since some of those names are used as template parameters.

Names starting with an underscore and upper case letter are reserved by the standard to be used by an implementation so I think the proper way to handle this is rename the template parameters. I didn't find a quick way to automate the renaming otherwise I would have made a pull request.

LnnrtS avatar Sep 09 '22 13:09 LnnrtS

Yeah this implementation is meant to go into the standard implementation hence we also use underscores, obviously we need to make it compatible with the ones we want to intregrate with. But seriously who injects single letter macros into the global namespace lol, almost as bad as MSVC definine MIN and MAX as macros ....

crtrott avatar Sep 10 '22 18:09 crtrott

On the other side I don't think there is a reason we should put _ in front of tempalte parameters in the first place.

crtrott avatar Sep 10 '22 18:09 crtrott

On the other side I don't think there is a reason we should put _ in front of tempalte parameters in the first place.

Right, I don't think it's our job necessarily to pre-mangle symbols. If a standard library implementation wants to adopt our reference mdspan implementation, they will do that mangling on their own.

This is a bit relevant to #185, though. We've been wanting to use a prefix _ as a way to mark macros as implementation details. On the other hand, "namespaced" macros like _MDSPAN_INLINE_FUNCTION probably won't collide with an existing standard library implementation's symbols.

mhoemmen avatar Sep 11 '22 22:09 mhoemmen

Correct me if I'm wrong but I don't think the name of template parameters have to be mangled at all because they are no symbols and they don't leave the scope of the template definition. But - as we can see in this particular issue - they are affected by global macros. So consequently I would say they actually may not be mangled at all.

LnnrtS avatar Sep 12 '22 11:09 LnnrtS

@LnnrtS wrote:

Correct me if I'm wrong but I don't think the name of template parameters have to be mangled at all because they are no symbols and they don't leave the scope of the template definition.

Just to clarify: The library in this repository does not need to mangle template parameters. Standard Library implementations of mdspan (which are coming) generally mangle symbols to avoid collisions with users' macros.

mhoemmen avatar Sep 12 '22 14:09 mhoemmen

Ok I see. I wasn't taking user defined macros into account (I mean, why would anybody.. ;-))

LnnrtS avatar Sep 12 '22 18:09 LnnrtS

We may wanna mangle but just use some larger names for the template parameters. That said I still think its insane to have in any library single letter macros, mangled or not.

crtrott avatar Sep 24 '22 14:09 crtrott