This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: swap does not compile


On Jan 12, 2004, Jonathan Wakely <cow@compsoc.man.ac.uk> wrote:

> On Mon, Jan 12, 2004 at 10:44:44AM +0100, Lars Gullik BjÃnnes wrote:
>> #include <vector>
>> #include <algorithm>
>> 
>> using std::swap;
>> 
>> int main() 
>> {
>> size_t a = 1;
>> size_t b = 2;
>> swap(a, b);
>> }
>> swap.C: In function `int main()':
>> swap.C:10: error: no matching function for call to `swap(size_t&, size_t&)'

> Is this more fallout from the strong-using work?

Not really.  cp_parser_name_lookup_name_simple() can return to
cp_parser_using_declaration() an overload involving functions in more
than one namespace, but then do_{local,toplevel}_using_decl() call
validate_nonmember_using_decl() that extracts the scope from the first
overload only.  This was already broken before the introduction of
strong using, e.g.:

namespace foo1 {
  template <class T> void f(T);
}
namespace foo2 {
  template <class T> void f(T, T);
}
namespace foo {
  using namespace foo1;
  using namespace foo2;
}

using foo::f;

int main() {
  f(1);
  f(1, 1);
}

However, the change in the lookup code so as to follow strong using
always has indeed had ill effects on the piece of code above, in that
it pushes the definition of __gnu_norm::swap into the overload list
after it pushes the definition of std::swap, so using std::swap ends
up being interpreted as using __gnu_norm::swap.

Before my recent change, what happened was that using std::swap had
the right meaning (as long as swap was indeed declared in namespace
std, instead of some other namespace brought in by a using namespace
directive), but we didn't find definitions of swap in
strongly-associated namespaces, so the testcase:

#include <vector>

using std::swap;

int main()
{
  vector<int> a, b;
  swap (a,b);
}

ended up silently choosing the wrong version of swap, namely, the
generic swap algorithm, instead of the specialized version of swap for
vectors.

Mark, Jason, any chance you could have a look into this.  Lars, will
you please open a bug report in bugzilla with the above testcase, and
maybe also this one?  Thanks,

namespace foo {
  template <class T> void f(T, T);
}
namespace fool {
  using namespace foo __attribute__((strong));
  template <class T> void f(T);
}

int main() {
  // Make sure both declarations are brought in.
  using fool::f;
  f(1);
  f(1, 1);
}


-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Happy GNU Year!                     oliva@{lsd.ic.unicamp.br, gnu.org}
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist                Professional serial bug killer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]