[patch] fix pr15930

Richard Smith richard at metafoo.co.uk
Wed May 15 22:08:12 PDT 2013


On Wed, May 15, 2013 at 9:44 PM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> On 15 May 2013 17:18, Richard Smith <richard at metafoo.co.uk> wrote:
> > Patch looks good, but don't you need to also change all the other calls
> to
> > QualType::getLinkageAndVisibility? In C++14 at least, a no-linkage type
> can
> > completely leak out of a function and be used as a type of a non-type
> > template parameter. For instance:
> >
> > inline auto f() {
> >   struct S {};
> >   return S();
> > }
> > template<decltype(f())*> struct X { X() {} };
> > X<nullptr> x;
> >
> > Right now, this incorrectly generates @x as an internal-linkage symbol.
> You
> > can probably observe the same bug in C++11 by passing S to a template
> like
> > this:
> >
> > template<typename T> struct Outer { template<T *p> struct Inner { ... };
> };
>
> So, I am trying to create a full c++11 testcase. The closest I have so far
> is
>
> template <typename T>
> struct foo {
>   template <T *P> static void f() {
>   }
>   static void *g() {
>     static T x;
>     return (void*)f<&x>;
>

Yeah, it's as you suspect: 'x' has no linkage, so its address can't be used
as a non-type template parameter. f<nullptr> here works, and exhibits the
bug. The following should also work, but is rejected, because we
incorrectly think that foo<S>::x has no linkage (with or without the inline
keyword):

template <typename T>
struct foo {
  template <T *P> static void f() {
  }
  static void *g() {
    f<&x>();
  }
  static T x;
};
template<typename T> T foo<T>::x;

/*inline*/ void *f() {
  struct S {
  };
  return foo<S>::g();
}

  }
> };
>
> inline void *f() {
>   struct S {
>   };
>   return foo<S>::g();
> }
>
> but this fails to compile with
>
> address of overloaded function 'f' does not match required type 'void'
>
> which I assume is because I am trying to use an object without linkage
> in a non type template argument. Is that supposed to work?
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130515/85756d29/attachment.html>


More information about the cfe-commits mailing list