From dc13ded6063942ff62f32b234ed016f70774d4f7 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 1 Jul 2010 00:00:45 +0000 Subject: [PATCH] Implement C++ DR481, which clarifies that the scope of template parameters starts at the end of the template-parameter rather than at the point where the template parameter name is encounted. For example, given: typedef unsigned char T; template struct X0 { }; The "T" in the default argument refers to the typedef of "unsigned char", rather than referring to the newly-introduced template type parameter 'T'. Addresses . llvm-svn: 107354 --- clang/include/clang/Parse/Action.h | 150 ++++++++++++++++------- clang/include/clang/Parse/Template.h | 2 +- clang/lib/Parse/ParseTemplate.cpp | 80 ++++++------- clang/lib/Sema/Sema.h | 22 ++-- clang/lib/Sema/SemaTemplate.cpp | 172 ++++++++++----------------- 5 files changed, 216 insertions(+), 210 deletions(-) diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h index fed4361f1ae5..678e62e10b3c 100644 --- a/clang/include/clang/Parse/Action.h +++ b/clang/include/clang/Parse/Action.h @@ -1833,46 +1833,87 @@ public: //===---------------------------C++ Templates----------------------------===// - /// ActOnTypeParameter - Called when a C++ template type parameter - /// (e.g., "typename T") has been parsed. Typename specifies whether - /// the keyword "typename" was used to declare the type parameter - /// (otherwise, "class" was used), ellipsis specifies whether this is a - /// C++0x parameter pack, EllipsisLoc specifies the start of the ellipsis, - /// and KeyLoc is the location of the "class" or "typename" keyword. - // ParamName is the name of the parameter (NULL indicates an unnamed template - // parameter) and ParamNameLoc is the location of the parameter name (if any) - /// If the type parameter has a default argument, it will be added - /// later via ActOnTypeParameterDefault. Depth and Position provide - /// the number of enclosing templates (see - /// ActOnTemplateParameterList) and the number of previous - /// parameters within this template parameter list. + /// \brief Called when a C++ template type parameter(e.g., "typename T") has + /// been parsed. + /// + /// Given + /// + /// \code + /// template struct pair; + /// \endcode + /// + /// this callback will be invoked twice: once for the type parameter \c T + /// with \p Depth=0 and \p Position=0, and once for the type parameter \c U + /// with \p Depth=0 and \p Position=1. + /// + /// \param Typename Specifies whether the keyword "typename" was used to + /// declare the type parameter (otherwise, "class" was used). + /// + /// \param Ellipsis Specifies whether this is a C++0x parameter pack. + /// + /// \param EllipsisLoc Specifies the start of the ellipsis. + /// + /// \param KeyLoc The location of the "class" or "typename" keyword. + /// + /// \param ParamName The name of the parameter, where NULL indicates an + /// unnamed template parameter. + /// + /// \param ParamNameLoc The location of the parameter name (if any). + /// + /// \param Depth The depth of this template parameter, e.g., the number of + /// template parameter lists that occurred outside the template parameter + /// list in which this template type parameter occurs. + /// + /// \param Position The zero-based position of this template parameter within + /// its template parameter list, which is also the number of template + /// parameters that precede this parameter in the template parameter list. + /// + /// \param EqualLoc The location of the '=' sign for the default template + /// argument, if any. + /// + /// \param DefaultArg The default argument, if provided. virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, SourceLocation EllipsisLoc, SourceLocation KeyLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, - unsigned Depth, unsigned Position) { + unsigned Depth, unsigned Position, + SourceLocation EqualLoc, + TypeTy *DefaultArg) { return DeclPtrTy(); } - /// ActOnTypeParameterDefault - Adds a default argument (the type - /// Default) to the given template type parameter (TypeParam). - virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam, - SourceLocation EqualLoc, - SourceLocation DefaultLoc, - TypeTy *Default) { - } - - /// ActOnNonTypeTemplateParameter - Called when a C++ non-type - /// template parameter (e.g., "int Size" in "template - /// class Array") has been parsed. S is the current scope and D is - /// the parsed declarator. Depth and Position provide the number of - /// enclosing templates (see - /// ActOnTemplateParameterList) and the number of previous - /// parameters within this template parameter list. + /// \brief Called when a C++ non-type template parameter has been parsed. + /// + /// Given + /// + /// \code + /// template class Array; + /// \endcode + /// + /// This callback will be invoked for the 'Size' non-type template parameter. + /// + /// \param S The current scope. + /// + /// \param D The parsed declarator. + /// + /// \param Depth The depth of this template parameter, e.g., the number of + /// template parameter lists that occurred outside the template parameter + /// list in which this template type parameter occurs. + /// + /// \param Position The zero-based position of this template parameter within + /// its template parameter list, which is also the number of template + /// parameters that precede this parameter in the template parameter list. + /// + /// \param EqualLoc The location of the '=' sign for the default template + /// argument, if any. + /// + /// \param DefaultArg The default argument, if provided. virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, unsigned Depth, - unsigned Position) { + unsigned Position, + SourceLocation EqualLoc, + ExprArg DefaultArg) { return DeclPtrTy(); } @@ -1883,29 +1924,50 @@ public: ExprArg Default) { } - /// ActOnTemplateTemplateParameter - Called when a C++ template template - /// parameter (e.g., "int T" in "template