[Bug c++/33129] New: C++ frontend finds static function in argument dependent lookup based on template parameter

ian at airs dot com gcc-bugzilla@gcc.gnu.org
Mon Aug 20 23:39:00 GMT 2007


In the C++ standard section 14.6.4.2 [temp.dep.candidate] says this:

"
For a function call that depends on a template parameter, if the function name
is an unqualified-id but not a template-id, the candidate functions are found
using the usual lookup rules (3.4.1, 3.4.2) except that:

-- For the part of the lookup using unqualified name lookup (3.4.1), only
function declarations with external linkage from the template definition
context are found.
"

If I understand this correctly, it seems to me that this code should fail to
compile:

template<typename t>
static void f(t v) { }

template<typename t>
void bar(t v) { f(v); }

void quux(int i) { bar(i); }

However, in fact, this does compile: bar<t> uses argument dependent lookup to
find f<t>, even though f<t> does not have external linkage.  Note that f does
not have to be a template; this program also compiles:

static void f(int v) { }

template<typename t>
void bar(t v) { f(v); }

void quux(int i) { bar(i); }

If I'm reading the standard correctly, then this is a minor case of the C++
frontend failing to properly diagnose an invalid C++ program.

I noticed this because of the Sun Studio's -features=templrefstatic option. 
The existence of this option means that if we do change the compiler, we need
to provide an option to implement the existing behaviour.  Perhaps we should
simply change the behaviour for -pedantic.


-- 
           Summary: C++ frontend finds static function in argument dependent
                    lookup based on template parameter
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33129



More information about the Gcc-bugs mailing list