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
[cpp.stringize] Whitespace is not a preprocessing token #4766
Comments
I agree that talking about a preprocessing token sequence already disregards whitespace (it's a sequence of tokens, after all), so it makes little sense to talk about the whitespace between preprocessing tokens in the sequence. What do you envision should be done here editorially? |
Consider this special case #define fun(x) #x
fun(&123)
It still does not comprise any whitespace. The concept "sequence of characters" is indispensable here. So, I would like to redefine what are the arguments for a function-like macro.
Since the effect of the whitespace is used to separate preprocessing tokens, whatever the number of whitespace between them in the original sequence of characters, it seems do not contribute to any case defined in [cpp], except that whether the existence of whitespace between them impacts the result of stringizing. In other words, the effect of multi whitespace is equivalent to that of single whitespace. The original relevant wording in [cpp.replace#cpp.stringize-2] could be modified to that
For instance #define test(x,y) #x#y For macro call test( &123 , c )its sequence of characters of the list of the arguments is &123 , c where the arguments are &123 and c .
For macro call test( & 123, c )its sequence of characters of the list of the arguments is & 123, c where the arguments are & 123 and c .
Simultaneously, [cpp.concat#2] could be modified to that
#define concat(x,y) x##y
concat( 1 2 , 3 ) Since the arguments are The second deleted wording sounds like #define concat2(x,y) x ## void y
concat( 1 2, 4) the parameter |
I agree that multiple whitespace is conflated to a single space in all cases. However, your examples (in particular the second one) show that the definition and formation of "preprocessing token sequence" itself is broken, and a fix should be applied there instead of to # and ## in isolation. Obviously, a "preprocessing token sequence" is intended to consist of preprocessing tokens, optionally separated by a single space. (Of course, the presence or absence of space only matters for # and ##.) Given that any work in this area appears to change the specified meaning of ##, this looks non-editorial to me. |
Regarding [cpp.concat] p2, I think the specification we have is sufficient: p2 says that the macro argument preprocessing token sequence is injected, and p3 says that only the single preprocessing tokens immediately preceding and following ## are spliced into a single preprocessing token. The rest of the tokens arriving by macro argument substitution survive unharmed; that's why you see "1 23" in the output (first example for cpp.concat above). |
Yes, you're right that [cpp.replace#cpp.subst-1] has covered the second case for [cpp.concat] above. The meaning of the sequence of preprocessing tokens is clear itself(namely, a sequence that consists of only valid preprocessing tokens ). The problem here is the intent definition for arguments has exceeded the ability of a sequence of preprocessing tokens since an argument can comprise the space for separating each preprocessing token. Hence, I think that we redefine the argument for the function-like macro to make the wording match the intent is reasonable. Yes, I know that this change has exceeded the extent of an editorial. Maybe, a more simple way is that
Consider the phase [lex.phases#1.3], "The source file is decomposed into preprocessing tokens ([lex.pptoken]) and sequences of whitespace characters (including comments).", the wording "sequence of characters" is not suitable in [cpp]. |
Asked CWG for guidance: http://lists.isocpp.org/core/2021/07/11276.php |
Consider [cpp.stringize]
Since whitespace is not a preprocessing token, the preprocessing token sequence should only consist of each preprocessing token that appears in the corresponding argument(i.e, a stringizing-argument does not contain whitespaces). This point is also highlighted in the answer of this issue
https://stackoverflow.com/a/37462188/11796722
The text was updated successfully, but these errors were encountered: