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

C++ literal errors #828

Closed
Anteru opened this issue Aug 31, 2019 · 6 comments
Closed

C++ literal errors #828

Anteru opened this issue Aug 31, 2019 · 6 comments
Labels
S-minor severity: minor T-bug type: a bug X-imported imported from Bitbucket

Comments

@Anteru
Copy link
Collaborator

Anteru commented Aug 31, 2019

(Original issue 1121 created by None on 2015-06-28T14:56:19.124666+00:00)

#!cpp

// integer literals:
234;        // decimal, OK
0234;       // octal, OK
0x1234abCD; // hexadecimal, OK
0X1234abCD; // hexadecimal, fail
0b1010;     // binary, fail
0B1010;     // binary, fail

1;        // OK
1u;       // OK
1U;       // OK
1l;       // OK
1L;       // OK
1ll;      // OK
1LL;      // OK
1ul;      // OK
1Ul;      // OK
1uL;      // OK
1UL;      // OK
1ull;     // OK
1Ull;     // OK
1uLL;     // OK
1ULL;     // OK

01;        // OK
01u;       // OK
01U;       // OK
01l;       // OK
01L;       // OK
01ll;      // OK
01LL;      // OK
01ul;      // OK
01Ul;      // OK
01uL;      // OK
01UL;      // OK
01ull;     // OK
01Ull;     // OK
01uLL;     // OK
01ULL;     // OK

0x1;        // OK
0x1u;       // OK
0x1U;       // OK
0x1l;       // OK
0x1L;       // OK
0x1ll;      // OK
0x1LL;      // OK
0x1ul;      // OK
0x1Ul;      // OK
0x1uL;      // OK
0x1UL;      // OK
0x1ull;     // OK
0x1Ull;     // OK
0x1uLL;     // OK
0x1ULL;     // OK

0b1;        // fail
0b1u;       // fail
0b1U;       // fail
0b1l;       // fail
0b1L;       // fail
0b1ll;      // fail
0b1LL;      // fail
0b1ul;      // fail
0b1Ul;      // fail
0b1uL;      // fail
0b1UL;      // fail
0b1ull;     // fail
0b1Ull;     // fail
0b1uLL;     // fail
0b1ULL;     // fail

// integer literals with ' as separator always fail:
1'123'456'789;    // same as 1234567890
0123'456;         // same as 0123456
0xABCD'1234;      // same as 0xABCD1234
0XABCD'1234;      // same as 0XABCD1234
0b1111'0000'0000; // same as 0b111100000000
0B1111'0000'0000; // same as 0B111100000000
// the ' can appear as separator on every position of an integer but for direct
// after a prefix (0, 0b, 0B, 0x or 0X), after another ' ('' is not allowed)
// and of course at the begin and after the last _digit_ (not suffix) of an integer literal

978'3'446'43981'8; // is a correct integer literal, same as 9783446439818
// (it is an ISBN, as example for a not equidistant separation use case)

// floating point literals:
4.24;    // OK
4.24f;   // OK
4.24F;   // OK
4.24l;   // The 'l' must be part of the literal
4.24L;   // The 'L' must be part of the literal

4.2e4;   // OK
4.2e+4;  // OK
4.2e-4;  // OK
4.2e4f;  // The 'f' must be part of the literal
4.2e+4f; // The 'f' must be part of the literal
4.2e-4f; // The 'f' must be part of the literal
4.2e4F;  // The 'F' must be part of the literal
4.2e+4F; // The 'F' must be part of the literal
4.2e-4F; // The 'F' must be part of the literal
4.2e4l;  // OK
4.2e+4l; // OK
4.2e-4l; // OK
4.2e4L;  // OK
4.2e+4L; // OK
4.2e-4L; // OK

4.2E4;   // OK
4.2E+4;  // OK
4.2E-4;  // OK
4.2E4f;  // The 'f' must be part of the literal
4.2E+4f; // The 'f' must be part of the literal
4.2E-4f; // The 'f' must be part of the literal
4.2E4F;  // The 'F' must be part of the literal
4.2E+4F; // The 'F' must be part of the literal
4.2E-4F; // The 'F' must be part of the literal
4.2E4l;  // OK
4.2E+4l; // OK
4.2E-4l; // OK
4.2E4L;  // OK
4.2E+4L; // OK
4.2E-4L; // OK

// character and c-string literals:
'a';            // OK
u'a';           // The 'u' must be part of the literal
U'a';           // The 'U' must be part of the literal
L'a';           // OK
"I am a Text";  // OK
u"I am a Text"; // The 'u' must be part of the literal
U"I am a Text"; // The 'U' must be part of the literal
L"I am a Text"; // OK

// also all raw string literals are not supported

// with C++17 the following literals will also become correct:
// --> begin C++17
u8'a';
u8"I am a Text";
// <-- end C++17
@Anteru Anteru added T-bug type: a bug X-imported imported from Bitbucket S-minor severity: minor labels Aug 31, 2019
@Anteru
Copy link
Collaborator Author

Anteru commented Aug 31, 2019

(Original issue was assigned to tshatch)

@Anteru
Copy link
Collaborator Author

Anteru commented Aug 31, 2019

(Original comment by bebuch on 2015-06-28T15:00:26.429123+00:00)

It's a report from me. I created a user account after posting.

@Anteru
Copy link
Collaborator Author

Anteru commented Aug 31, 2019

(Original comment by tshatch on 2015-10-17T02:32:51.925943+00:00)

Thanks for the thorough repro.

@Anteru
Copy link
Collaborator Author

Anteru commented Aug 31, 2019

(Original comment by drhouck on 2017-05-10T15:53:48.911189+00:00)

Since the creation of this issue, u, u8, and U prefixed string literals were fixed, but not the character literals and not anything else.

Would a PR for some of these issues be welcome? I haven’t made the changes so I can’t guarantee I’ll be able to fix them, but I plan to at least give it a shot and I don’t expect any issues.

If you would like a PR, I do have a question. How should user-defined literal suffixes be handled? Should they be part of the literal like the builtin suffixes are, or should they be some token type under Name (or just Name itself, as they are now)?

@Anteru
Copy link
Collaborator Author

Anteru commented Aug 31, 2019

(Original comment by bebuch on 2017-05-11T08:52:35.603536+00:00)

The suffixes and prefixes are always part of the literals, so it would be best to make them part of ;-)

@Anteru
Copy link
Collaborator Author

Anteru commented May 22, 2020

Fixed by #1350

@Anteru Anteru closed this as completed May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-minor severity: minor T-bug type: a bug X-imported imported from Bitbucket
Projects
None yet
Development

No branches or pull requests

1 participant