[llvm-bugs] [Bug 44175] New: unused member variable causes code to compile for member to function for undefined function
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 28 18:12:27 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44175
Bug ID: 44175
Summary: unused member variable causes code to compile for
member to function for undefined function
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++17
Assignee: unassignedclangbugs at nondot.org
Reporter: marcpawl at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
https://godbolt.org/z/VygQuN
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
https://godbolt.org/z/SFZmZJ
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191129/3577a85e/attachment.html>
More information about the llvm-bugs
mailing list