[cfe-dev] Visibility of inline defined friend template function

Richard Smith richard at metafoo.co.uk
Tue Jul 9 14:46:22 PDT 2013


On Tue, Jul 9, 2013 at 2:32 PM, Will Wilson <will at indefiant.com> wrote:
> Thanks Richard. [temp.arg.explicit]p8 uses namespaces in the example which
> threw me. Anyhow, I'll take a look at adding support for this when in MS
> mode. I assume it shouldn't be too hard to do...?

Does MSVC perform friend injection in general, or does it just somehow
manage to parse DoT as a template name in this case? For instance:

struct S {
  friend void f() {}
  template<typename T> friend void g(T) {}
};
void h() {
  f(); // ok?
  g(S()); // ok?
  g<S>(S{}); // ok?
  g<int>(0); // ok?
}

... and what happens if you add:

  int f, g;

prior to the class definition? What happens if you add them to an
enclosing namespace?

> On 9 July 2013 22:17, Richard Smith <richard at metafoo.co.uk> wrote:
>>
>> On Tue, Jul 9, 2013 at 8:38 AM, Will Wilson <will at indefiant.com> wrote:
>> > Hi All,
>> >
>> > A quick question regarding correct behaviour:
>> >
>> > class Vec3 {
>> > public:
>> > friend void DoA(Vec3& a) {
>> > a.m_int = 1;
>> > }
>> >
>> > template <const bool B>
>> > friend void DoT(Vec3& a) {
>> > if (B)
>> > a.m_int = 2;
>> > }
>> > private:
>> > int m_int;
>> > };
>> >
>> > void test_friend_functions_inline() {
>> > Vec3 a;
>> > DoA(a);
>> > DoT<true>(a);  // error: use of undeclared identifier 'DoT'
>>
>> Lookup of DoT here finds nothing, so this is parsed as a comparison
>> rather than as a template. EDG rejects this in its strict mode.
>>
>> See [temp.arg.explicit]p8, which has almost exactly this case as an
>> example.
>
>
>
>
> --
> Indefiant Ltd.
>
> Firsby Lodge, New Main Road, Scamblesby, Louth, Lincs LN11 9XH UK
> Tel: +44 20 8123 7663 England Registered No. 07936820 VAT No. 128556202



More information about the cfe-dev mailing list