title: Different behaviour of my type_trait in templated/non-templated code
body: <p>In the following snippet, the <code>has_bar</code> behaves differently in the main and the <code>DoStuff</code> method:</p>
  
  <p>In the main method, <code>a_bar == false</code> and <code>b_bar == true</code>.</p>
  
  <p>When I execute this, I get 2x "Foo" as output. Why?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A
  {
      void Foo() { std::cout &lt;&lt; "Foo" &lt;&lt; std::endl; }
  };
  
  struct B : public A
  {
      void Bar() {  std::cout &lt;&lt; "Bar" &lt;&lt; std::endl; }
  };
  
  template&lt;typename, typename = void&gt;
  struct has_bar : std::false_type
  { };
  
  template&lt;typename T&gt;
  struct has_bar&lt;T, std::void_t&lt;decltype(T::Bar)&gt;&gt; : std::true_type
  { };
  
  template&lt;typename T&gt;
  void DoStuff(T t)
  {
      if constexpr (has_bar&lt;T&gt;::value)
      {
          t.Bar();
      }
      else
      {
          t.Foo();
      }
  }
  
  
  int main()
  {
      A a;
      B b;
  
      constexpr bool a_bar = has_bar&lt;A&gt;::value; // false
      constexpr bool b_bar = has_bar&lt;B&gt;::value; // true
  
      DoStuff(a);
      DoStuff(b);
  
      std::cin.ignore();
  
      return 0;
  }
  </code></pre>