<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - unused member variable causes code to compile for member to function for undefined function"
   href="https://bugs.llvm.org/show_bug.cgi?id=44175">44175</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>unused member variable causes code to compile for member to function for undefined function
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>marcpawl@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/VygQuN">https://godbolt.org/z/VygQuN</a>

If the class is not instantiated and the variable is not static then the
reference to a non-existing method is not reported as an error.


#include <type_traits>
#include <cstdio>
struct Foo {
  virtual void hello(int) = 0;
};

struct Bar : public Foo {
void hello(int) override {};
};

struct Bad {  };

template <typename T>
struct is_Foo {
    using hello_fn_t = void (T::*)(int);
    void (T::*hello)(int) = &T::hello; 
    constexpr static bool value=true;
};

template <typename T, typename U=is_Foo<T>>
void say(T& t)
{
    static_assert(U::value, "not a Foo");
    puts("hello\n");
    //U u; // Line 22
    //t.hello(4); // Line 23
}



int main()
{
    //Bar b;;
    //Foo& f = b;
    //say(b);
    //say(f);
    Bad bad;
    say(bad);
}


====
Found while exploring a GCC bug
to gcc-bugzilla-account-request

<a href="https://godbolt.org/z/SFZmZJ">https://godbolt.org/z/SFZmZJ</a>

In clang you get 
no member names 'hello' in 'Bad'
which is the expected result.

In all GCC versions using --std=c++17 from 5.2 onwards the code compiles.

#include <type_traits>
#include <cstdio>
struct Foo {
virtual void hello(int) = 0;
};

struct Bar : public Foo {
void hello(int) override {};
};

struct Bad { };

template <typename T>
struct is_Foo {
using hello_fn_t = void (T::*)(int);
constexpr static void (T::*hello)(int) = &T::hello;
static constexpr bool value=true;
};

template <typename T>
auto say(T& t) -> std::enable_if_t<is_Foo<T>::value, void>{
//U u; // Line 22
//t.hello(4); // Line 23
puts("hello\n");
}

int main()
{
//Bar b;;
//Foo& f = b;
//say(b);
//say(f);
Bad bad;
say(bad);
}

If you change say to
template <typename T, typename U=is_Foo<T>>
void say(T& t)
{
    U u; // Line 22
    //t.hello(4); // Line 23
}
you get the same errors in clang, but no errors in gcc.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>