From b8a9a41dd6ea0b0d652edb5be0a78dd21e0e271d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 4 Feb 2009 15:01:18 +0000 Subject: Fix our semantic analysis of unqualified-id '(' in C++. The unqualified-id might not refer to any declaration in our current scope, but declarations by that name might be found via argument-dependent lookup. We now do so properly. As part of this change, CXXDependentNameExpr, which was previously designed to express the unqualified-id in the above constructor within templates, has become UnresolvedFunctionNameExpr, which does effectively the same thing but will work for both templates and non-templates. Additionally, we cope with all unqualified-ids, since ADL also applies in cases like operator+(x, y) llvm-svn: 63733 --- clang/include/clang/AST/ExprCXX.h | 39 +++++++++++++++++++++-------------- clang/include/clang/AST/StmtNodes.def | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) (limited to 'clang/include') diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 4f48eb3716a..26f3b6c1610 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -727,28 +727,35 @@ public: static CXXDeleteExpr * CreateImpl(llvm::Deserializer& D, ASTContext& C); }; -/// CXXDependentNameExpr - Represents a dependent name in C++ for -/// which we could not locate any definition. These names can only -/// occur as in the example below, with an unqualified call to a -/// function name whose arguments are dependent. +/// \brief Represents the name of a function that has not been +/// resolved to any declaration. +/// +/// Unresolved function names occur when a function name is +/// encountered prior to an open parentheses ('(') in a C++ function +/// call, and the function name itself did not resolve to a +/// declaration. These function names can only be resolved when they +/// form the postfix-expression of a function call, so that +/// argument-dependent lookup finds declarations corresponding to +/// these functions. + /// @code /// template void f(T x) { -/// g(x); // g is a dependent name. +/// g(x); // g is an unresolved function name (that is also a dependent name) /// } /// @endcode -class CXXDependentNameExpr : public Expr { - /// Name - The name that was present in the source code. - IdentifierInfo *Name; +class UnresolvedFunctionNameExpr : public Expr { + /// The name that was present in the source + DeclarationName Name; - /// Loc - The location + /// The location of this name in the source code SourceLocation Loc; public: - CXXDependentNameExpr(IdentifierInfo *N, QualType T, SourceLocation L) - : Expr(CXXDependentNameExprClass, T, true, true), Name(N), Loc(L) { } + UnresolvedFunctionNameExpr(DeclarationName N, QualType T, SourceLocation L) + : Expr(UnresolvedFunctionNameExprClass, T, false, false), Name(N), Loc(L) { } - /// getName - Retrieves the name that occurred in the source code. - IdentifierInfo *getName() const { return Name; } + /// \brief Retrieves the name that occurred in the source code. + DeclarationName getName() const { return Name; } /// getLocation - Retrieves the location in the source code where /// the name occurred. @@ -757,16 +764,16 @@ public: virtual SourceRange getSourceRange() const { return SourceRange(Loc); } static bool classof(const Stmt *T) { - return T->getStmtClass() == CXXDependentNameExprClass; + return T->getStmtClass() == UnresolvedFunctionNameExprClass; } - static bool classof(const CXXDependentNameExpr *) { return true; } + static bool classof(const UnresolvedFunctionNameExpr *) { return true; } // Iterators virtual child_iterator child_begin(); virtual child_iterator child_end(); virtual void EmitImpl(llvm::Serializer& S) const; - static CXXDependentNameExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); + static UnresolvedFunctionNameExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); }; /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the diff --git a/clang/include/clang/AST/StmtNodes.def b/clang/include/clang/AST/StmtNodes.def index 18b8dbebfed..0d289f55f3b 100644 --- a/clang/include/clang/AST/StmtNodes.def +++ b/clang/include/clang/AST/StmtNodes.def @@ -115,7 +115,7 @@ STMT(CXXZeroInitValueExpr , Expr) STMT(CXXConditionDeclExpr , DeclRefExpr) STMT(CXXNewExpr , Expr) STMT(CXXDeleteExpr , Expr) -STMT(CXXDependentNameExpr , Expr) +STMT(UnresolvedFunctionNameExpr , Expr) STMT(UnaryTypeTraitExpr , Expr) STMT(QualifiedDeclRefExpr , DeclRefExpr) -- cgit v1.2.1