<div dir="ltr">On 2 May 2013 12:25, João Matos <<a href="mailto:ripzonetriton@gmail.com">ripzonetriton@gmail.com</a>> wrote:<br>> My patch is probably an hack, and I don't know enough about the preprocessor works to understand how to do the correct fix without spending a lot of time researching it. Your explanation sounds interesting though.<div>
<br></div><div style>Actually, having taken another look at your patch, it looks like it could almost do the job. Rather than just ignoring all expanded commas, I've made a change where all freshly expanded tokens are ignored by the lexer when first passed over, which seems to be doing the job so far. The below patch is a quick hack that doesn't check if we're running in ms-compatibility mode yet, still testing if it's actually ms-compatibile.</div>
<div style><br></div><div style>Still a hack, but I suspect a non-hack ms-compatibilty for this would involve some major reshuffling of the lexer.</div><div style><br></div><div style>--------</div><div style><br></div><div style>
<div>diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h</div><div>index bcbe9c9..d3a2118 100644</div><div>--- a/include/clang/Lex/Token.h</div><div>+++ b/include/clang/Lex/Token.h</div><div>@@ -77,7 +77,8 @@ public:</div>
<div> NeedsCleaning = 0x08, // Contained an escaped newline or trigraph.</div><div> LeadingEmptyMacro = 0x10, // Empty macro exists before this token.</div><div> HasUDSuffix = 0x20, // This string or character literal has a ud-suffix.</div>
<div>- HasUCN = 0x40 // This identifier contains a UCN.</div><div>+ HasUCN = 0x40, // This identifier contains a UCN.</div><div>+ FreshExpanded = 0x80 // This token was a recent macro expansion.</div>
<div> };</div><div> </div><div> tok::TokenKind getKind() const { return (tok::TokenKind)Kind; }</div><div>diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp</div><div>index 1678233..96980f6 100644</div>
<div>--- a/lib/Lex/PPMacroExpansion.cpp</div><div>+++ b/lib/Lex/PPMacroExpansion.cpp</div><div>@@ -450,6 +450,8 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,</div><div> EnterTokenStream(Toks, 1, true, true);</div>
<div> break;</div><div> }</div><div>+ } else if (Tok.getFlags() & Token::FreshExpanded) {</div><div>+ Tok.clearFlag(Token::FreshExpanded);</div><div> } else if (Tok.is(tok::r_paren)) {</div>
<div> // If we found the ) token, the macro arg list is done.</div><div> if (NumParens-- == 0) {</div><div>diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp</div><div>index 07753c7..ae19b82 100644</div>
<div>--- a/lib/Lex/TokenLexer.cpp</div><div>+++ b/lib/Lex/TokenLexer.cpp</div><div>@@ -282,6 +282,7 @@ void TokenLexer::ExpandFunctionArguments() {</div><div> Token &Tok = ResultToks[i];</div><div> if (Tok.is(tok::hashhash))</div>
<div> Tok.setKind(tok::unknown);</div><div>+ Tok.setFlag(Token::FreshExpanded);</div><div> }</div><div> </div><div> if(ExpandLocStart.isValid()) {</div><div><br></div></div></div>