dimanche 1 mai 2022

Why argument-dependent lookup is not triggered?

I am trying to find out why this piece of code doesn't trigger ADL:

#include <stdio.h>

namespace N {
    struct S {
        int z = 10;
    };
    int increase(int x) {return x + 10;}
}

int f(N::S x) {
    return increase(10) + 5;
}

int main() {
    N::S s;
    printf("%d", f(s));
    return 0;
}

compiling with clang gives me:

error: use of undeclared identifier 'increase'; did you mean 'N::increase'?

My understanding is: because the argument has type of N::S, the namespace of N is looked up so that int increase(int) will be located? No? Any suggestion is welcome!

Aucun commentaire:

Enregistrer un commentaire