[cfe-commits] [Request for approval] Redundant NNS and missing template keyword

Abramo Bagnara abramo.bagnara at gmail.com
Tue Jul 27 03:01:25 PDT 2010


Please find attached a couple of patches that are meant to fix the
problems shown by the following examples.

==============
$ cat bug1.cc
template <typename T>
struct Outer {
  template <typename U>
  struct Inner {
    Inner& foo();
  };
};


template <typename T>
template <typename U>
typename Outer<T> ::template Inner<U>&
Outer<T>::Inner<U>::foo() {}
==============

If this is pretty printed using clang, we obtain the following:

==============
$ llvm/Debug+Asserts/bin/clang -cc1 -ast-print bug1.cc
struct __va_list_tag {
    unsigned int gp_offset;
    unsigned int fp_offset;
    void *overflow_arg_area;
    void *reg_save_area;
};
typedef struct __va_list_tag __va_list_tag;
template <typename T> struct Outer {
    template <typename U> struct Inner {
        Inner<U> &foo();
    };
};
typename Outer<T>::Outer<T>::Inner<U> &foo() {
}
==============

The printed return type in the out-of-line definition of method foo has
two problems: the name qualification Outer<T>:: is repeated and the name
qualification Inner<U> is missing the "template" keyword.

The first problem is due to the fact that the NNS is encoded *both* in
the ElaboratedType and in the underlying (dependent)
TemplateSpecializationType: this should be corrected in redundant-nns.patch

The second problem is caused by method Sema::isTemplateName(), which
sometimes builds a QualifiedTemplateName disregarding whether or not the
"template" keyword was specified: this should be corrected in
template-keyword.patch

After applying both patches we obtain:
===============
$ llvm/Debug+Asserts/bin/clang -cc1 -ast-print bug1.cc
[...]
typename Outer<T>::template Inner<U> &foo() {
}
===============

-------------- next part --------------
A non-text attachment was scrubbed...
Name: redundant-nns.patch
Type: text/x-patch
Size: 2201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100727/26b10939/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: template-keyword.patch
Type: text/x-patch
Size: 7993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100727/26b10939/attachment-0001.bin>


More information about the cfe-commits mailing list