2

Let's say that we have a simple main.cpp file which contains only a single call of a function bar which is defined in the module a:

import a;

int main() {
    bar(1);
}

Then let's take a look at the module a:

export module a;

namespace N {

struct adl_tag {};

void foo(adl_tag, auto) {}

} // namespace N

export void bar(auto v) {
    return foo(N::adl_tag{}, v);
}

There we have an exported function template bar, which invokes N::foo using argument-dependent lookup. The function foo, however, is not exported and is not visible from the outside code.

Godbolt link: https://godbolt.org/z/6Waqbj6zh

clang 21 compiles this project just fine but gcc 15 fails with an error:

In instantiation of ‘void bar@a(auto:2) [with auto:2 = int]’:
error: ‘foo’ was not declared in this scope

Which compiler is right here?

2
  • Clang should be correct : basic.lookup.argdep. Calling foo(N::adl_tag{}, v) inside bar should trigger ADL then look in namespace N where foo is visible. So ADL should find foo Commented 39 mins ago
  • @PepijnKramer But before ADL can kick in, isn't it required that unqualified lookup first finds a function named foo. I don't see how such a lookup would succeed. So, I think that GCC is right. Commented 16 mins ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.