Topic: ADL: should this compile?


Author: Jason McKesson <jmckesson@gmail.com>
Date: Sun, 22 Apr 2012 11:52:41 -0700 (PDT)
Raw View
GCC version 4.7 seems to have fixed a bug
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29131), but I'm wondering
if it caused another.

Should this C++ code compile? I think ADL requires it to, but I'm not certain.

template<class T>
int t(T i)
{
 return f(i);
}

struct a{};

int f(a i)
{
 return 0;
}

int main()
{
 a b;
 return t(b);
}


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]




Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?=<daniel.kruegler@googlemail.com>
Date: Sun, 22 Apr 2012 13:52:49 -0700 (PDT)
Raw View
Am 22.04.2012 20:52, schrieb Jason McKesson:
[..]
>  Should this C++ code compile? I think ADL requires it to, but I'm not certain.
>
>  template<class T>
>  int t(T i)
>  {
>    return f(i);
>  }
>
>  struct a{};
>
>  int f(a i)
>  {
>    return 0;
>  }
>
>  int main()
>  {
>    a b;
>    return t(b);
>  }

Yes, this clearly is supposed to work according to ADL rules. All recent
compilers I know of (including gcc 4.8) accept this example as they should.

HTH&  Greetings from Bremen,

Daniel Kr   gler


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]