https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96204
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-07-15
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Keywords| |rejects-valid
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Klaus Rudolph from comment #0)
> Full code example:
The example is incomplete, and you didn't say how you're compiling it.
This is the complete example, and requires -std=c++17
#include <type_traits>
#include <iostream>
using std::void_t;
using std::cout;
using std::endl;
template <typename, typename = void_t<>>
struct has_set_attr_method {
static constexpr bool value = false;
};
template <typename T>
struct has_set_attr_method<T, void_t<decltype(std::declval<T>().setAttr(1))>> {
static constexpr bool value = true;
};
struct Parent
{
public:
template<typename T>
static void create() {
auto obj = T::create();
if constexpr(has_set_attr_method<T>::value) {
cout << "has setAttr" << endl;
} else {
cout << "no setAttr" << endl;
}
}
};
struct Child : public Parent {
public:
friend class Parent;
static auto create() {
return Child();
}
private:
void setAttr(int) {
}
};
int main() {
Parent::create<Child>();
}
#include <type_traits>
#include <iostream>
using std::void_t;
using std::cout;
using std::endl;
(In reply to Klaus Rudolph from comment #1)
> Maybe related to: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64335
I don't think so, that is "accepts-invalid" not "rejects-valid" and it was
fixed years ago.