www.digitalmars.com         C & C++   DMDScript  

c++ - Koenig lookup failure with templates

reply "Matthew Wilson" <matthew thedjournal.com> writes:
Walter, a template bug for you, which I found when trying it out on one of
the STLSoft classes.

Included is an extract (templ_tt.cpp) from stlsoft_true_typedef.h (the
original can be found at http://stlsoft.org), which is a template class for
generating strong ("true") typedefs. When compiled, as included, 8.28 fails
with

sc templ_tt.cpp
templ_tt.cpp(79) : Error: 'true_typedef' is not a class template templ_tt.cpp(83) : Error: 'v' is not in function parameter list templ_tt.cpp(85) : Error: '=', ';' or ',' expected templ_tt.cpp(86) : Error: '=', ';' or ',' expected return 0; ^ templ_tt.cpp(105) : Error: '=', ';' or ',' expected Fatal error: too many errors --- errorlevel 1 When compiled with namespaces suspended it works fine
sc -D_STLSOFT_NO_NAMESPACES templ_tt.cpp
link templ_tt,,,user32+kernel32/noi; It appears that Koenig lookup is kind of right, in that the compiler locates the operator, but then loses the original context. I've included a non-template version (non_templ_tt.cpp) which demonstrates that it is indeed the templates that are introducing the confusion. Have fun. :) Matthew begin 666 templ_tt.zip M-ID^3E[^3&?/+[/GNZ?[R>O=^'YB;"[X L)<P"D+P3)4!:,8=R7X(!2*F"\ M'*\52QWTJFGZUF):"OZWS;;I_)H$OMT"6%E;4S*FO(YSH< TTCP7!_H:!'[7 MG' CR&96FE\+]+OVS 3G?9H_^%X0!==["OS(^*%8.Q;92G? TP*O]4-')NJ0 MA8X"M]_C,O^."?(")=.YA)LOV"V%YTCA!AHNJA1ZGD1=2 $]G7!U57NDW-Y% M$2J52[6?V,I;G4'HS)FJMBZ0+EB;6H#S47MV.?J2Y#MX)?()LSE6$F6N,=(8 MCPZH82]BPCS0"\ ,A6;;MI%\14_"`NG^.== ;"L>8SP`INRXH:&AV3O0P$DI M<H TX?'HES_\;1NK]7;HW1B;;2%='2_I%Y7Q'U!+`P04````" "8 NPLV* 2 M!* !``!&! ``$ ```&YO;E]T96UP;%]T="YC<'"E4<MJPS 0/"N0?]A3\2/( MF?N!4GHZ/W^ 9AQAHU4'!ENC-KA&/8 U'GI1B0VM3]C]?E]"C!JQ+XO"IJ Y M2&$:0[GJ*!N**.(9EW')"!"J]/;LZDGU!]UL:X3D*87%?+Z8P2I(P\JB]TP+ M>,,#O&+E_4/RVG AC:A D)70 +48,U;(9,5T93.#Y (BIPS^;K?1!IPIC(V6 MUMBUZ:\3_'OPMP(RV_WQDZP3IF?6X6F G],)X2TS!AKY<RFVX(HD7HFMDQUK M(V#I]$ _O-L>2 >[IB=<28-P9L"=/Z<.3$KHUOZ:G).?7UZ37!/).S/A%"DI M4?%N-W.,]#BQ MYG8VEX;M'?<35UJ6U^^2%XG7N=#S+P4[3=+P^V3QX&W=1"S(H\/E>5"*+<^7 MOHUO4$L!`A0`% ```` `6H'L+)Q,,V3O` ``I ```P``````````0` `+:! M`````'1E;7!L7W1T+F-P<%!+`0(4`!0````(`)B"["S8J!($J $``$8$```0 *> ```.\$```````` ` end
Jul 11 2002
parent reply "Walter" <walter digitalmars.com> writes:
I haven't implemented Koenig lookup rules yet :-(

"Matthew Wilson" <matthew thedjournal.com> wrote in message
news:agls97$seh$1 digitaldaemon.com...
 Walter, a template bug for you, which I found when trying it out on one of
 the STLSoft classes.

 Included is an extract (templ_tt.cpp) from stlsoft_true_typedef.h (the
 original can be found at http://stlsoft.org), which is a template class
for
 generating strong ("true") typedefs. When compiled, as included, 8.28
fails
 with

sc templ_tt.cpp
templ_tt.cpp(79) : Error: 'true_typedef' is not a class template templ_tt.cpp(83) : Error: 'v' is not in function parameter list templ_tt.cpp(85) : Error: '=', ';' or ',' expected templ_tt.cpp(86) : Error: '=', ';' or ',' expected return 0; ^ templ_tt.cpp(105) : Error: '=', ';' or ',' expected Fatal error: too many errors --- errorlevel 1 When compiled with namespaces suspended it works fine
sc -D_STLSOFT_NO_NAMESPACES templ_tt.cpp
link templ_tt,,,user32+kernel32/noi; It appears that Koenig lookup is kind of right, in that the compiler
locates
 the operator, but then loses the original context.

 I've included a non-template version (non_templ_tt.cpp) which demonstrates
 that it is indeed the templates that are introducing the confusion.

 Have fun. :)

 Matthew
Jul 12 2002
next sibling parent reply "Matthew Wilson" <matthew thedjournal.com> writes:
But you must have something similar, since the non-template version works
correctly.

Or am I being dumb? (Note: the probability of this in the general case is
greater than 82.73%, and in this specific case 82.77%)

"Walter" <walter digitalmars.com> wrote in message
news:agm45p$15l5$1 digitaldaemon.com...
 I haven't implemented Koenig lookup rules yet :-(

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:agls97$seh$1 digitaldaemon.com...
 Walter, a template bug for you, which I found when trying it out on one
of
 the STLSoft classes.

 Included is an extract (templ_tt.cpp) from stlsoft_true_typedef.h (the
 original can be found at http://stlsoft.org), which is a template class
for
 generating strong ("true") typedefs. When compiled, as included, 8.28
fails
 with

sc templ_tt.cpp
templ_tt.cpp(79) : Error: 'true_typedef' is not a class template templ_tt.cpp(83) : Error: 'v' is not in function parameter list templ_tt.cpp(85) : Error: '=', ';' or ',' expected templ_tt.cpp(86) : Error: '=', ';' or ',' expected return 0; ^ templ_tt.cpp(105) : Error: '=', ';' or ',' expected Fatal error: too many errors --- errorlevel 1 When compiled with namespaces suspended it works fine
sc -D_STLSOFT_NO_NAMESPACES templ_tt.cpp
link templ_tt,,,user32+kernel32/noi; It appears that Koenig lookup is kind of right, in that the compiler
locates
 the operator, but then loses the original context.

 I've included a non-template version (non_templ_tt.cpp) which
demonstrates
 that it is indeed the templates that are introducing the confusion.

 Have fun. :)

 Matthew
Jul 14 2002
parent reply "Walter" <walter digitalmars.com> writes:
Koenig lookup only applies to namespaces, so that's why it worked without
namespaces.

"Matthew Wilson" <matthew thedjournal.com> wrote in message
news:agt0av$3md$1 digitaldaemon.com...
 But you must have something similar, since the non-template version works
 correctly.

 Or am I being dumb? (Note: the probability of this in the general case is
 greater than 82.73%, and in this specific case 82.77%)

 "Walter" <walter digitalmars.com> wrote in message
 news:agm45p$15l5$1 digitaldaemon.com...
 I haven't implemented Koenig lookup rules yet :-(

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:agls97$seh$1 digitaldaemon.com...
 Walter, a template bug for you, which I found when trying it out on
one
 of
 the STLSoft classes.

 Included is an extract (templ_tt.cpp) from stlsoft_true_typedef.h (the
 original can be found at http://stlsoft.org), which is a template
class
 for
 generating strong ("true") typedefs. When compiled, as included, 8.28
fails
 with

sc templ_tt.cpp
templ_tt.cpp(79) : Error: 'true_typedef' is not a class template templ_tt.cpp(83) : Error: 'v' is not in function parameter list templ_tt.cpp(85) : Error: '=', ';' or ',' expected templ_tt.cpp(86) : Error: '=', ';' or ',' expected return 0; ^ templ_tt.cpp(105) : Error: '=', ';' or ',' expected Fatal error: too many errors --- errorlevel 1 When compiled with namespaces suspended it works fine
sc -D_STLSOFT_NO_NAMESPACES templ_tt.cpp
link templ_tt,,,user32+kernel32/noi; It appears that Koenig lookup is kind of right, in that the compiler
locates
 the operator, but then loses the original context.

 I've included a non-template version (non_templ_tt.cpp) which
demonstrates
 that it is indeed the templates that are introducing the confusion.

 Have fun. :)

 Matthew
Jul 14 2002
parent reply "Matthew Wilson" <matthew thedjournal.com> writes:
That's not what I said. I mentioned that it worked with KL in the
non-template version, not the non-namespace version.

The non-template version is thus:

/* /////////////////////////////////////////////////////////////
 *
 * ...
 *
 * Extract from stlsoft_true_typedef.h
 *
 * www:        http://www.synesis.com.au/stlsoft
 *             http://www.stlsoft.org/
 *
 * Copyright (C) 2002, Synesis Software Pty Ltd.
 * (Licensed under the Synesis Software Standard Source License:
 *  http://www.synesis.com.au/licenses/ssssl.html)
 *
 * ...
 *
 * ////////////////////////////////////////////////////////// */

namespace stlsoft
{
 class int_true_typedef
 {
  typedef int value_type;

 public:
  int_true_typedef(const value_type &value)
   : m_value(value)
  {}

  const value_type base_type_value() const
  {
   return m_value;
  }

 protected:
  value_type m_value;
 };

 inline const int_true_typedef operator ++(int_true_typedef &v, int)
 {
  return int_true_typedef(v.base_type_value() + 1);
 }
}

int main(int /* argc */, char ** /* argv */)
{
 typedef stlsoft::int_true_typedef Intint_true_typedef;

 Intint_true_typedef    ic1(23);
 Intint_true_typedef    ic2 = ic1++;

 return 0;
}

so you can see that there are still namespaces involved, and it must be
doing some kind of (Koenig-like) lookup in order to get the operator ++ out
of the stlsoft namespace, no?

:)

Matthew


"Walter" <walter digitalmars.com> wrote in message
news:agtc2p$equ$1 digitaldaemon.com...
 Koenig lookup only applies to namespaces, so that's why it worked without
 namespaces.

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:agt0av$3md$1 digitaldaemon.com...
 But you must have something similar, since the non-template version
works
 correctly.

 Or am I being dumb? (Note: the probability of this in the general case
is
 greater than 82.73%, and in this specific case 82.77%)

 "Walter" <walter digitalmars.com> wrote in message
 news:agm45p$15l5$1 digitaldaemon.com...
 I haven't implemented Koenig lookup rules yet :-(

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:agls97$seh$1 digitaldaemon.com...
 Walter, a template bug for you, which I found when trying it out on
one
 of
 the STLSoft classes.

 Included is an extract (templ_tt.cpp) from stlsoft_true_typedef.h
(the
 original can be found at http://stlsoft.org), which is a template
class
 for
 generating strong ("true") typedefs. When compiled, as included,
8.28
 fails
 with

sc templ_tt.cpp
templ_tt.cpp(79) : Error: 'true_typedef' is not a class template templ_tt.cpp(83) : Error: 'v' is not in function parameter list templ_tt.cpp(85) : Error: '=', ';' or ',' expected templ_tt.cpp(86) : Error: '=', ';' or ',' expected return 0; ^ templ_tt.cpp(105) : Error: '=', ';' or ',' expected Fatal error: too many errors --- errorlevel 1 When compiled with namespaces suspended it works fine
sc -D_STLSOFT_NO_NAMESPACES templ_tt.cpp
link templ_tt,,,user32+kernel32/noi; It appears that Koenig lookup is kind of right, in that the compiler
locates
 the operator, but then loses the original context.

 I've included a non-template version (non_templ_tt.cpp) which
demonstrates
 that it is indeed the templates that are introducing the confusion.

 Have fun. :)

 Matthew
Jul 14 2002
parent reply "Walter" <walter digitalmars.com> writes:
Sorry I read what I expected to see and not what you'd actually written! And
the answer is I don't know at the moment. The namespace implementation isn't
right, and I'm going to immerse myself in fixing all the namespace bugs
after I get the template stuff all up to speed. It's the only way I have a
hope of getting this stuff done.

"Matthew Wilson" <matthew thedjournal.com> wrote in message
news:agtgqi$j34$1 digitaldaemon.com...
 That's not what I said. I mentioned that it worked with KL in the
 non-template version, not the non-namespace version.

 The non-template version is thus:

 /* /////////////////////////////////////////////////////////////
  *
  * ...
  *
  * Extract from stlsoft_true_typedef.h
  *
  * www:        http://www.synesis.com.au/stlsoft
  *             http://www.stlsoft.org/
  *
  * Copyright (C) 2002, Synesis Software Pty Ltd.
  * (Licensed under the Synesis Software Standard Source License:
  *  http://www.synesis.com.au/licenses/ssssl.html)
  *
  * ...
  *
  * ////////////////////////////////////////////////////////// */

 namespace stlsoft
 {
  class int_true_typedef
  {
   typedef int value_type;

  public:
   int_true_typedef(const value_type &value)
    : m_value(value)
   {}

   const value_type base_type_value() const
   {
    return m_value;
   }

  protected:
   value_type m_value;
  };

  inline const int_true_typedef operator ++(int_true_typedef &v, int)
  {
   return int_true_typedef(v.base_type_value() + 1);
  }
 }

 int main(int /* argc */, char ** /* argv */)
 {
  typedef stlsoft::int_true_typedef Intint_true_typedef;

  Intint_true_typedef    ic1(23);
  Intint_true_typedef    ic2 = ic1++;

  return 0;
 }

 so you can see that there are still namespaces involved, and it must be
 doing some kind of (Koenig-like) lookup in order to get the operator ++
out
 of the stlsoft namespace, no?

 :)

 Matthew
Jul 15 2002
parent reply "Matthew Wilson" <matthew thedjournal.com> writes:
No worries.

I shall look forward to giving you lots more material.

:)


"Walter" <walter digitalmars.com> wrote in message
news:agtvdt$14n5$1 digitaldaemon.com...
 Sorry I read what I expected to see and not what you'd actually written!
And
 the answer is I don't know at the moment. The namespace implementation
isn't
 right, and I'm going to immerse myself in fixing all the namespace bugs
 after I get the template stuff all up to speed. It's the only way I have a
 hope of getting this stuff done.

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:agtgqi$j34$1 digitaldaemon.com...
 That's not what I said. I mentioned that it worked with KL in the
 non-template version, not the non-namespace version.

 The non-template version is thus:

 /* /////////////////////////////////////////////////////////////
  *
  * ...
  *
  * Extract from stlsoft_true_typedef.h
  *
  * www:        http://www.synesis.com.au/stlsoft
  *             http://www.stlsoft.org/
  *
  * Copyright (C) 2002, Synesis Software Pty Ltd.
  * (Licensed under the Synesis Software Standard Source License:
  *  http://www.synesis.com.au/licenses/ssssl.html)
  *
  * ...
  *
  * ////////////////////////////////////////////////////////// */

 namespace stlsoft
 {
  class int_true_typedef
  {
   typedef int value_type;

  public:
   int_true_typedef(const value_type &value)
    : m_value(value)
   {}

   const value_type base_type_value() const
   {
    return m_value;
   }

  protected:
   value_type m_value;
  };

  inline const int_true_typedef operator ++(int_true_typedef &v, int)
  {
   return int_true_typedef(v.base_type_value() + 1);
  }
 }

 int main(int /* argc */, char ** /* argv */)
 {
  typedef stlsoft::int_true_typedef Intint_true_typedef;

  Intint_true_typedef    ic1(23);
  Intint_true_typedef    ic2 = ic1++;

  return 0;
 }

 so you can see that there are still namespaces involved, and it must be
 doing some kind of (Koenig-like) lookup in order to get the operator ++
out
 of the stlsoft namespace, no?

 :)

 Matthew
Jul 15 2002
parent "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew thedjournal.com> wrote in message
news:agvj7t$2rk0$1 digitaldaemon.com...
 No worries.

 I shall look forward to giving you lots more material.

 :)
I know that writing a good bug report is hard work, but they are much appreciated. After they are fixed, they also wind up in the test suite so they stay fixed.
Jul 15 2002
prev sibling parent "Matthew Wilson" <matthew thedjournal.com> writes:
Is this slated for attention in a soon-to-be-released version?

"Walter" <walter digitalmars.com> wrote in message
news:agm45p$15l5$1 digitaldaemon.com...
 I haven't implemented Koenig lookup rules yet :-(

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:agls97$seh$1 digitaldaemon.com...
 Walter, a template bug for you, which I found when trying it out on one
of
 the STLSoft classes.

 Included is an extract (templ_tt.cpp) from stlsoft_true_typedef.h (the
 original can be found at http://stlsoft.org), which is a template class
for
 generating strong ("true") typedefs. When compiled, as included, 8.28
fails
 with

sc templ_tt.cpp
templ_tt.cpp(79) : Error: 'true_typedef' is not a class template templ_tt.cpp(83) : Error: 'v' is not in function parameter list templ_tt.cpp(85) : Error: '=', ';' or ',' expected templ_tt.cpp(86) : Error: '=', ';' or ',' expected return 0; ^ templ_tt.cpp(105) : Error: '=', ';' or ',' expected Fatal error: too many errors --- errorlevel 1 When compiled with namespaces suspended it works fine
sc -D_STLSOFT_NO_NAMESPACES templ_tt.cpp
link templ_tt,,,user32+kernel32/noi; It appears that Koenig lookup is kind of right, in that the compiler
locates
 the operator, but then loses the original context.

 I've included a non-template version (non_templ_tt.cpp) which
demonstrates
 that it is indeed the templates that are introducing the confusion.

 Have fun. :)

 Matthew
Jul 14 2002