[cfe-commits] r99390 - /cfe/trunk/lib/Sema/SemaDecl.cpp

Douglas Gregor dgregor at apple.com
Wed Mar 24 07:28:14 PDT 2010


Nice catch.

Sent from my iPhone

On Mar 24, 2010, at 1:27 AM, John McCall <rjmccall at apple.com> wrote:

> Author: rjmccall
> Date: Wed Mar 24 03:27:58 2010
> New Revision: 99390
>
> URL: http://llvm.org/viewvc/llvm-project?rev=99390&view=rev
> Log:
> Correct that last fixit:  if the user wrote
>  template <> friend void foo(int);
> we need to change it to
>  friend void foo<>(int);
> or else the user won't get the template specialization they  
> obviously want.
>
>
> Modified:
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=99390&r1=99389&r2=99390&view=diff
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 24 03:27:58 2010
> @@ -2921,9 +2921,24 @@
>
>       // C++0x [temp.expl.spec]p20 forbids "template<> void foo 
> (int);".
>       if (isFriend && isFunctionTemplateSpecialization) {
> -        SourceRange Range = TemplateParams->getSourceRange();
> +        // We want to remove the "template<>", found here.
> +        SourceRange RemoveRange = TemplateParams->getSourceRange();
> +
> +        // If we remove the template<> and the name is not a
> +        // template-id, we're actually silently creating a problem:
> +        // the friend declaration will refer to an untemplated decl,
> +        // and clearly the user wants a template specialization.  So
> +        // we need to insert '<>' after the name.
> +        SourceLocation InsertLoc;
> +        if (D.getName().getKind() != UnqualifiedId::IK_TemplateId) {
> +          InsertLoc = D.getName().getSourceRange().getEnd();
> +          InsertLoc = PP.getLocForEndOfToken(InsertLoc);
> +        }
> +
>         Diag(D.getIdentifierLoc(),  
> diag::err_template_spec_decl_friend)
> -          << Name << Range << CodeModificationHint::CreateRemoval 
> (Range);
> +          << Name << RemoveRange
> +          << CodeModificationHint::CreateRemoval(RemoveRange)
> +          << CodeModificationHint::CreateInsertion(InsertLoc, "<>");
>       }
>     }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list