LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 7396 - candidate function chosen improperly in type dependent context
Summary: candidate function chosen improperly in type dependent context
Status: RESOLVED WONTFIX
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-17 02:06 PDT by Nick Lewycky
Modified: 2012-06-12 22:26 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Lewycky 2010-06-17 02:06:39 PDT
Clang (and gcc and comeau) accept the following invalid program:

  static void test1(int *) { }
  
  template<typename T>
  int *test2(const T &) { return 0; }
  
  template<typename T>
  void test3(const T &t) {
    test1(test2(t));
  }

The statement "test1(test2(t))" is type-dependent all the way through to test1. 14.6.4.2/1 second bullet states:
  "For the part of the lookup using associated namespace (3.4.2), only function declarations with external linkage found in either the template definition context or the template instantiation context are found."

test1() does not have external linkage. If we remove 'static' or change test1 to ::test1 (see the rest of the referenced section) then the program becomes valid.
Comment 1 Chandler Carruth 2010-06-17 02:14:41 PDT
(In reply to comment #0)
> Clang (and gcc and comeau) accept the following invalid program:
> 
>   static void test1(int *) { }
> 
>   template<typename T>
>   int *test2(const T &) { return 0; }
> 
>   template<typename T>
>   void test3(const T &t) {
>     test1(test2(t));
>   }
> 
> The statement "test1(test2(t))" is type-dependent all the way through to test1.
> 14.6.4.2/1 second bullet states:
>   "For the part of the lookup using associated namespace (3.4.2), only function
> declarations with external linkage found in either the template definition
> context or the template instantiation context are found."

Just to clarify, the first bullet is the one that governs from 14.6.4.2/1, but it too restricts to functions with external linkage.

> 
> test1() does not have external linkage. If we remove 'static' or change test1
> to ::test1 (see the rest of the referenced section) then the program becomes
> valid.
Comment 2 Jeffrey Yasskin 2010-06-17 02:17:15 PDT
And this is fixed in C++0x, which says:

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

— For the part of the lookup using associated namespaces (3.4.2), only function declarations found in 
either the template definition context or the template instantiation context are found. "
Comment 3 Richard Smith 2012-06-12 22:26:28 PDT
This was CWG issue 561, and I think it's reasonable to consider this a bug in C++98 rather than a bug in Clang :)