aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Parse/Action.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-21 23:18:07 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-21 23:18:07 +0000
commit1fd6d44d7ca97631497551bbf98866263143d706 (patch)
treed55684a3629ba44cddbe0b9d29897c19e6663f3f /include/clang/Parse/Action.h
parentdb3f847cb883fdb19d79c7223fa032e7266c0ee5 (diff)
Improve parser recovery when we encounter a dependent template name
that is missing the 'template' keyword, e.g., t->getAs<T>() where getAs is a member of an unknown specialization. C++ requires that we treat "getAs" as a value, but that would fail to parse since T is the name of a type. We would then fail at the '>', since a type cannot be followed by a '>'. This is a very common error for C++ programmers to make, especially since GCC occasionally allows it when it shouldn't (as does Visual C++). So, when we are in this case, we use tentative parsing to see if the tokens starting at "<" can only be parsed as a template argument list. If so, we produce a diagnostic with a fix-it that states that the 'template' keyword is needed: test/SemaTemplate/dependent-template-recover.cpp:5:8: error: 'template' keyword is required to treat 'getAs' as a dependent template name t->getAs<T>(); ^ template This is just a start of this patch; I'd like to apply the same approach to everywhere that a template-id with dependent template name can be parsed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104406 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Parse/Action.h')
-rw-r--r--include/clang/Parse/Action.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 69105685ba..f9aef9b0e9 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -286,13 +286,18 @@ public:
/// \param Template if the name does refer to a template, the declaration
/// of the template that the name refers to.
///
+ /// \param MemberOfUnknownSpecialization Will be set true if the resulting
+ /// member would be a member of an unknown specialization, in which case this
+ /// lookup cannot possibly pass at this time.
+ ///
/// \returns the kind of template that this name refers to.
virtual TemplateNameKind isTemplateName(Scope *S,
CXXScopeSpec &SS,
UnqualifiedId &Name,
TypeTy *ObjectType,
bool EnteringContext,
- TemplateTy &Template) = 0;
+ TemplateTy &Template,
+ bool &MemberOfUnknownSpecialization) = 0;
/// \brief Action called as part of error recovery when the parser has
/// determined that the given name must refer to a template, but
@@ -3027,7 +3032,9 @@ public:
UnqualifiedId &Name,
TypeTy *ObjectType,
bool EnteringContext,
- TemplateTy &Template);
+ TemplateTy &Template,
+ bool &MemberOfUnknownSpecialization);
+
/// ActOnDeclarator - If this is a typedef declarator, we modify the
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is