Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5995293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:56:21+00:00 2026-05-22T23:56:21+00:00

Reading questions, comments and answers on SO, I hear all the time that MSVC

  • 0

Reading questions, comments and answers on SO, I hear all the time that MSVC doesn’t implement two-phase template lookup / instantiation correctly.

From what I understand so far, MSVC++ is only doing a basic syntax check on template classes and functions and doesn’t check that names used in the template have atleast been declared or something along those lines.

Is this correct? What am I missing?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:56:22+00:00Added an answer on May 22, 2026 at 11:56 pm

    I’ll just copy an example from my “notebook”

    int foo(void*);
    
    template<typename T> struct S {
      S() { int i = foo(0); }
      // A standard-compliant compiler is supposed to 
      // resolve the 'foo(0)' call here (i.e. early) and 
      // bind it to 'foo(void*)'
    };
    
    void foo(int);
    
    int main() {
      S<int> s;
      // VS2005 will resolve the 'foo(0)' call here (i.e. 
      // late, during instantiation of 'S::S()') and
      // bind it to 'foo(int)', reporting an error in the 
      // initialization of 'i'
    }
    

    The above code is supposed to compile in a standard C++ compiler. However, MSVC (2005 as well as 2010 Express) will report an error because of incorrect implementation of two-phase lookup.


    And if you look closer, the issue is actually two-layered. At the surface, it is the obvious fact that Microsoft’s compiler fails to perform early (first phase) lookup for a non-dependent expression foo(0). But what it does after that does not really behave as a proper implementation of the second lookup phase.

    The language specification clearly states that during the second lookup phase only ADL-nominated namespaces get extended with additional declarations accumulated between the point of definition and point of instantiation. Meanwhile, non-ADL lookup (i.e. ordinary unqualified name lookup) is not extended by the second phase – it still sees those and only those declarations that were visible at the first phase.

    That means that in the above example the compiler is not supposed to see void foo(int) at the second phase either. In other words, the MSVC’s behavior cannot be described by a mere “MSVC postpones all lookup till the second phase”. What MSVC implements is not a proper implementation of the second phase either.

    To better illustrate the issue, consider the following example

    namespace N {
      struct S {};
    }
    
    void bar(void *) {}
    
    template <typename T> void foo(T *t) {
      bar(t);
    }
    
    void bar(N::S *s) {}
    
    int main() {
      N::S s;
      foo(&s);
    }
    

    Note that even though bar(t) call inside the template definition is a dependent expression resolved at the second lookup phase, it should still resolve to void bar(void *). In this case ADL does not help the compiler to find void bar(N::S *s), while the regular unqualified lookup is not supposed to get “extended” by the second phase and thus is not supposed to see void bar(N::S *s) either.

    Yet, Microsoft’s compiler resolves the call to void bar(N::S *s). This is incorrect.

    The problem is still present in its original glory in VS2015.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading a couple of answers and comments on some SQL questions here, and
After reading several questions regarding problems with compilation (particularly C++) and noticing that in
I've been reading similar questions, but many of the answers are outdated or not
Reading through some of the questions here, the general concensus seems to be that
Reading some questions here on SO about conversion operators and constructors got me thinking
I've been reading similar questions to this issue and have been able to get
I've been reading the other questions dealing with master pages, but I didn't see
There are questions pertaining to reading settings from a separate config file and others
I was reading the docs and some questions around here and couldn't understand how
Reading across difference lineage of CPU created by intel , many questions aroused in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.