Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22004

Constructor SFINAE and inheritence fails in clang

$
0
0

The following code compiles fine under GCC but fails in clang with the error:

no matching constructor for initialization of 'Bar'

The problem seems to be that clang thinks the template constructor of Foo is hidden or overwritten by the template constructor of Bar.

Is this a bug in clang or a non standardized feature in GCC?

How to fix this problem? I cannot change Foo since it is 3rd party.

#include <type_traits>

struct Foo {
    Foo() = default;

    template<typename T, std::enable_if_t<std::is_trivially_copyable_v<T>>* = nullptr>
    Foo(T& object) {}
};

struct Bar : public Foo {

    using Foo::Foo;

    template<typename T, std::enable_if_t<!std::is_trivially_copyable_v<T>>* = nullptr>
    Bar(T& object) {}
};

int main() {
    int i;
    Bar s{i};
}

https://gcc.godbolt.org/z/etvpvF


Viewing all articles
Browse latest Browse all 22004

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>