c++: Function found via ADL when it should not [PR95074]
commit90b160f8ec515f54ddc36519a6aaa60abdabdec1
authorMarek Polacek <polacek@redhat.com>
Tue, 12 May 2020 18:56:13 +0000 (12 14:56 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 12 May 2020 20:25:51 +0000 (12 16:25 -0400)
tree8b4b63c44002d4b6cd0aee527a86957dda357dd7
parentac627eb4162d31aa4d009c3c9a8da7dfd6cc34e0
c++: Function found via ADL when it should not [PR95074]

I noticed that we don't implement [basic.lookup.argdep]/3: quite correctly;
it says "If X (the lookup set produced by unqualified lookup) contains
-- a block-scope function declaration that is not a using-declaration
[...]
then Y (the lookup set produced by ADL) is empty."
but we were still performing ADL in fn1 in the attached test.  The
problem was that we were only looking at the first function in the
overload set which in this case happened to be a using-declaration, and
those don't suppress ADL.  We have to look through the whole set to find
out if unqualified lookup found a block-scope function declaration, or
a member function declaration.

PR c++/95074
* parser.c (cp_parser_postfix_expression) <case CPP_OPEN_PAREN>: When
looking for a block-scope function declaration, look through the whole
set, not just the first function in the overload set.

* g++.dg/lookup/koenig15.C: New test.
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/koenig15.C [new file with mode: 0644]