Bug 44320 - ADL names are looked up in namespaces that are only referenced by template arguments
Summary: ADL names are looked up in namespaces that are only referenced by template ar...
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-29 07:41 UTC by Stefan Straßer
Modified: 2010-05-29 09:30 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0 4.5.1 4.6.0
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Straßer 2010-05-29 07:41:20 UTC
I believe that the following is a bug. it is accepted by MSVC and comeau.

GCC seems to ADL-lookup names in namespaces that are only used in the template arguments of the function arguments, for example:

A<otherns::type> a;
adl_func(a); //otherns::adl_func is called

this can cause unintended conflicts with non-function names in "otherns", e.g. if the ADL function is called "apply" and the argument type happens to be a template instantiated with a type from namespace boost::mpl, only the fact that a header containing the type boost::mpl::apply is included can cause a compile error.

here's a simplified test case that causes a conflict:


namespace mpl{
  class apply{};
  class vector{};
}


template<class T>
void apply(T const &){}

template<class T>
class A{};

int main(){
  A<mpl::vector> a;
  apply(a);
}
Comment 1 Stefan Straßer 2010-05-29 07:45:47 UTC
a workaround (other than renaming the ADL function) would be appreciated
Comment 2 Paolo Carlini 2010-05-29 09:30:59 UTC
Works fine in 4_5-branch and mainline, the behavior in 4_3-branch and 4_4-branch isn't a regression in any way, as fas as I can see.