diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Parse/Parser.cpp | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 17b14bd2a1b..66b1d180780 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -424,7 +424,11 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) { Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { if (getLang().CPlusPlus) { // Annotate typenames and C++ scope specifiers. - // Used only in C++; in C let the typedef name be handled as an identifier. + // Used only in C++, where the typename can be considered as a functional + // style cast ("int(1)"). + // In C we don't expect identifiers to be treated as typenames; if it's a + // typedef name, let it be handled as an identifier and + // Actions.ActOnIdentifierExpr will emit the proper diagnostic. TryAnnotateTypeOrScopeToken(); } diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index ec07b423193..42d95e7f02e 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -700,6 +700,15 @@ Parser::ExprResult Parser::ParseSimpleAsm() { /// This simplifies handling of C++ scope specifiers and allows efficient /// backtracking without the need to re-parse and resolve nested-names and /// typenames. +/// It will mainly be called when we expect to treat identifiers as typenames +/// (if they are typenames). For example, in C we do not expect identifiers +/// inside expressions to be treated as typenames so it will not be called +/// for expressions in C. +/// The benefit for C/ObjC is that a typename will be annotated and +/// Actions.isTypeName will not be needed to be called again (e.g. isTypeName +/// will not be called twice, once to check whether we have a declaration +/// specifier, and another one to get the actual type inside +/// ParseDeclarationSpecifiers). void Parser::TryAnnotateTypeOrScopeToken() { if (Tok.is(tok::annot_qualtypename) || Tok.is(tok::annot_cxxscope)) return; |

