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

[version.syn] Add digit separators between year and month #5117

Closed
wants to merge 1 commit into from

Conversation

jensmaurer
Copy link
Member

@jensmaurer jensmaurer commented Nov 20, 2021

Fixes #5109

digsep

@timsong-cpp
Copy link
Contributor

The exact spelling of the macro is observable to stringization and token concatenation though?

@jensmaurer
Copy link
Member Author

Do you have an example? This one isn't one:

#include <iostream>

#define date 2019'07L

#define S(x) #x

int main()
{
  std::cout << S(date) << std::endl;
}

outputs date.

@JohelEGP
Copy link
Contributor

https://godbolt.org/z/Wq64xrand

#define date 2019'07L
#define cat(x, y) x ## y
#define S(y) cat(x, y)
const char s[] = S(date);
<source>:3:18: error: pasting &quot;x&quot; and &quot;2019'07L&quot; does not give a valid preprocessing token
    3 | #define S(y) cat(x, y)
      |                  ^
<source>:2:19: note: in definition of macro 'cat'
    2 | #define cat(x, y) x ## y
      |                   ^
<source>:4:18: note: in expansion of macro 'S'
    4 | const char s[] = S(date);
      |                  ^
<source>:3:18: error: 'x' was not declared in this scope
    3 | #define S(y) cat(x, y)
      |                  ^
<source>:2:19: note: in definition of macro 'cat'
    2 | #define cat(x, y) x ## y
      |                   ^
<source>:4:18: note: in expansion of macro 'S'
    4 | const char s[] = S(date);
      |                  ^
<source>:4:18: error: pasting formed 'x2019'07L', an invalid preprocessing token
const char s[] = S(date);
                 ^
<source>:3:14: note: expanded from macro 'S'
#define S(y) cat(x, y)
             ^
<source>:2:21: note: expanded from macro 'cat'
#define cat(x, y) x ## y
                    ^
<source>:4:18: error: use of undeclared identifier 'x'
<source>:3:14: note: expanded from macro 'S'
#define S(y) cat(x, y)
             ^
<source>:2:19: note: expanded from macro 'cat'
#define cat(x, y) x ## y
                  ^
<source>:3:18: note: expanded from macro 'x'
#define S(y) cat(x, y)
                 ^
<source>:4:20: error: expected ';' after top level declarator
const char s[] = S(date);
                   ^
<source>:1:14: note: expanded from macro 'date'
#define date 2019'07L
             ^
3 errors generated.
example.cpp
<source>(4): error C2001: newline in constant
<source>(4): error C2065: 'x2019': undeclared identifier
<source>(4): error C2143: syntax error: missing ';' before 'constant'
<source>(4): error C2059: syntax error: 'constant'

@jensmaurer
Copy link
Member Author

jensmaurer commented Nov 23, 2021

Ok. Without the digit separator, we get:

#define date 201907L
#define cat(x, y) x ## y
#define S(y) cat(x, y)

const char s[] = S(date);

which yields

x.cc:6:18: error: ‘x201907L’ was not declared in this scope
    6 | #define S(y) cat(x, y)

i.e. we get a valid identifier.

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Nov 23, 2021
@jensmaurer
Copy link
Member Author

@jwakely , do you feel we should file a library issue to make the presence or absence of digit separators in feature-test macros unspecified, thus making the concatenation magic shown in this issue not portable?

@jwakely
Copy link
Member

jwakely commented Nov 23, 2021

I don't see any advantage to allowing them. Six digits, where the first four are a recent year, doesn't seem too hard to read without separators.

I want going to comment here if everybody else liked the idea, but I don't actually like the results with the separators.

@jensmaurer
Copy link
Member Author

So, this is not editorial (because adding the digit separator breaks preprocessor token concatenation). The absence of digit separators is not a defect (thus an LWG issue is not the right thing).
This leaves for anyone who cares deeply to write a paper.

@jensmaurer jensmaurer closed this Nov 23, 2021
@jensmaurer jensmaurer removed the decision-required A decision of the editorial group (or the Project Editor) is required. label Nov 23, 2021
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.

[version.syn] Use a digit separator to split the year and the month
4 participants