]> granicus.if.org Git - clang/commitdiff
Introduce a new token kind 'cxx_defaultarg_end' to mark the end of C++ default argume...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 6 Aug 2010 09:47:24 +0000 (09:47 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 6 Aug 2010 09:47:24 +0000 (09:47 +0000)
lexed method declarations.

This avoid interference with tokens coming after the point where the default arg tokens were 'injected', e.g. for

typedef struct Inst {
  void m(int x=0);
} *InstPtr;

when parsing '0' the next token would be '*' and things would be messed up.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110436 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TokenKinds.def
lib/Parse/ParseCXXInlineMethods.cpp
lib/Parse/ParseDecl.cpp
test/Parser/cxx-default-args.cpp

index b16b82854b1c8aae5618a28c8be2b4a7401ac293..a20260381a3628343a6f227a0432a9135b7c387a 100644 (file)
@@ -96,6 +96,7 @@ TOK(unknown)             // Not a token.
 TOK(eof)                 // End of file.
 TOK(eom)                 // End of macro (end of line inside a macro).
 TOK(code_completion)     // Code completion marker
+TOK(cxx_defaultarg_end)  // C++ default argument end marker
 
 // C99 6.4.9: Comments.
 TOK(comment)             // Comment (only in -E -C[C] mode)
index 62a7ecd5d4903d9241e986c8fecbcb38d6a3d7b9..9f12ab501e43a8776614e017dd1d3cdc6a4494cf 100644 (file)
@@ -142,9 +142,13 @@ void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {
         OwningExprResult DefArgResult(ParseAssignmentExpression());
         if (DefArgResult.isInvalid())
           Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param);
-        else
+        else {
+          assert(Tok.is(tok::cxx_defaultarg_end) &&
+                 "We didn't parse the whole default arg!");
+          ConsumeToken(); // Consume tok::cxx_defaultarg_end.
           Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
                                             move(DefArgResult));
+        }
 
         assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
                                                            Tok.getLocation()) &&
index 6f65640d605e213cc9a5b74ed0469c5e51e7f8cc..65b4fb77adc03c3f4cc7946119842bc3a94fcd8c 100644 (file)
@@ -3085,9 +3085,17 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
             delete DefArgToks;
             DefArgToks = 0;
             Actions.ActOnParamDefaultArgumentError(Param);
-          } else
+          } else {
+            // Mark the end of the default argument so that we know when to
+            // stop when we parse it later on.
+            Token DefArgEnd;
+            DefArgEnd.startToken();
+            DefArgEnd.setKind(tok::cxx_defaultarg_end);
+            DefArgEnd.setLocation(Tok.getLocation());
+            DefArgToks->push_back(DefArgEnd);
             Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
                                                 (*DefArgToks)[1].getLocation());
+          }
         } else {
           // Consume the '='.
           ConsumeToken();
index a084fb0812bace6c8e1b1c00a72bceaaa3232cbc..a7bb5eeda8b5187355f26ad1b92f9ac30a2cde62 100644 (file)
@@ -7,3 +7,6 @@ class C {
   void m(int x = undecl + 0); // expected-error {{use of undeclared identifier 'undecl'}}
 };
 
+typedef struct Inst {
+  void m(int x=0);
+} *InstPtr;