Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsigned long Maxcode = 0x10ffff #6050

Closed
notbob-at-tessellation-com opened this issue Jan 18, 2023 · 7 comments
Closed

unsigned long Maxcode = 0x10ffff #6050

notbob-at-tessellation-com opened this issue Jan 18, 2023 · 7 comments

Comments

@notbob-at-tessellation-com

Hello,

Today I am making my first posts to this group. Please forgive me if I make mistakes. Thank you.

Here is the context:

D.21.2 Header synopsis [depr.codecvt.syn]
namespace std {
enum codecvt_mode {
consume_header = 4,
generate_header = 2,
little_endian = 1
};
template<class Elem, unsigned long Maxcode = 0x10ffff, codecvt_mode Mode = (codecvt_mode)0>
class codecvt_utf8 : public codecvt<Elem, char, mbstate_t> {
public:
explicit codecvt_utf8(size_t refs = 0);
~codecvt_utf8();
};
template<class Elem, unsigned long Maxcode = 0x10ffff, codecvt_mode Mode = (codecvt_mode)0>
class codecvt_utf16 : public codecvt<Elem, char, mbstate_t> {
public:
explicit codecvt_utf16(size_t refs = 0);
~codecvt_utf16();
};
template<class Elem, unsigned long Maxcode = 0x10ffff, codecvt_mode Mode = (codecvt_mode)0>
class codecvt_utf8_utf16 : public codecvt<Elem, char, mbstate_t> {
public:
explicit codecvt_utf8_utf16(size_t refs = 0);
~codecvt_utf8_utf16();
};
}

Yes, I know it is deprecated, but perhaps this is a more general question.

The constant 0x10ffff is of type int.
The template parameter formal Maxcode is of type unsigned long.
Would it be more clear and type-correct if the constant were 0x10ffffUL?

Thank you,

Robert Schwartz

@jwakely
Copy link
Member

jwakely commented Jan 18, 2023

The constant 0x10ffff is of type int.

That depends on the size of int. For an implementation where int is 16 bits, that constant will have type long.

@jwakely
Copy link
Member

jwakely commented Jan 18, 2023

But whatever the type, it can convert to unsigned long without changing the value. I'm not really persuaded that adding a suffix is more clear, and there's nothing incorrect about it.

@notbob-at-tessellation-com
Copy link
Author

@notbob-at-tessellation-com
Copy link
Author

@tkoeppe
Copy link
Contributor

tkoeppe commented Jan 18, 2023

I didn't mean to imply anything was incorrect. I was only trying to see if it could be made completely type-safe, with no need for any questions about conversion.

I appreciate the concern, but I don't think it is currently either incompletely type-safe of completely type-unsafe. I don't think this code raises any meaningful questions, as @jwakely pointed out. Yes, one could change it, but one could also just leave it as is.

@notbob-at-tessellation-com
Copy link
Author

@jensmaurer
Copy link
Member

The standard library specification assumes a conforming compiler; there is nothing wrong with "unsigned long Maxcode = 0x10ffff" beyond opinion-laden consideration of code aesthetics.

@jensmaurer jensmaurer closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2023
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

No branches or pull requests

4 participants