https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92735
Bug ID: 92735
Summary: unused member variable causes code to compile for
member to function for undefined function
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marcpawl at gmail dot com
Target Milestone: ---
Marc Pawlowsky <[email protected]>
Thu, Nov 28, 8:25 PM (23 hours ago)
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.
==
on a related not I sent to clang bug report where if value is not static the
code will compile.